Re: [firedrake] Solver error -- Provided residual is not a linear form
Hi Anna, The proximate cause of your error is line 24 of solvers.py which contains multiple subexpressions of the form: Z0 - H - tan(a)*(x-L)) Here, Z0 is a Function but x is a numpy array containing coordinate values. You are therefore subtracting a numpy array from a Function. This makes no mathematical sense and, unsurprisingly, causes UFL to choke. Regards, David On Mon, 15 May 2017 at 13:25 Homolya, Miklós <m.homolya14@imperial.ac.uk> wrote:
If you want to preserve the symbolic structure of maximum and its dependence on u, then you need neither interpolate nor assign.
maximum = 0.5*(u + abs(u)) F = v*(u + maximum)*dx
On 15/05/17 10:06, Anna Kalogirou wrote:
Hi David,
What I would like to do is to define a residual that includes some nonlinear function depending on the unknown, similar to the example with the maximum below (ultimately, I need to use functions abs, exp, tan). I do want to dependence of maximum on u to appear in the definition of the residual somehow; how can I do that then?
Thanks,
Anna.
On 15 May 2017, at 09:44, David Ham <David.Ham@imperial.ac.uk> wrote:
On Sun, 14 May 2017 at 21:31 Anna Kalogirou <A.Kalogirou@leeds.ac.uk> wrote:
Following up on my previous email, I have found a workaround to those issues, but now I have a problem with the solvers:
Traceback (most recent call last): File "/Users/matak/Downloads/Inequality-constraint-Rockafellar/solvers.py", line 32, in solver_F F_problem = NonlinearVariationalProblem(F_solve, w)#, aP=Ap) File "/Users/matak/firedrake/src/firedrake/firedrake/variational_solver.py", line 47, in __init__ raise ValueError("Provided residual is not a linear form") ValueError: Provided residual is not a linear form
There two issues here: 1. I cannot give a preconditioning matrix aP -- is this not possible for nonlinear problems?
As the documentation for NonlinearVariationalProblem suggests, you can provide Jp, a UFL form for the preconditioning Jacobian. This is the equivalent of aP.
2. I suspect the error above is because I have functions that depend on the solution, and I don’t know if that is acceptable in firedrake. I have something like the following:
u = Function(V) v = TestFunction(V) maximum = interpolate(0.5*(u + abs(u)), V) F = v*(u + maximum)*dx
Actually, as Colin sort of says, as far as Firedrake is concerned, maximum does not depend on u. This is because doing the interpolation breaks the symbolic link between u and maximum. In the code you have written, maximum does not get updated inside the variational solver as the guess for u gets updated. Whether that is what you wanted to do or not depends on the maths of your problem.
The error you are seeing, however, is caused by the Form having two arguments. This almost certainly means you have a TrialFunction in your nonlinear problem, which makes no sense.
Regards,
David
Best wishes,
Anna.
-- Dr David Ham Department of Mathematics Imperial College London
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing listfiredrake@imperial.ac.ukhttps://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr David Ham Department of Mathematics Imperial College London
Hi David, Thank you for spotting my mistake. Indeed, I should have interpolated x[0] into a Function. Regards, Anna. On 15 May 2017, at 13:49, David Ham <David.Ham@imperial.ac.uk<mailto:David.Ham@imperial.ac.uk>> wrote: Hi Anna, The proximate cause of your error is line 24 of solvers.py which contains multiple subexpressions of the form: Z0 - H - tan(a)*(x-L)) Here, Z0 is a Function but x is a numpy array containing coordinate values. You are therefore subtracting a numpy array from a Function. This makes no mathematical sense and, unsurprisingly, causes UFL to choke. Regards, David On Mon, 15 May 2017 at 13:25 Homolya, Miklós <m.homolya14@imperial.ac.uk<mailto:m.homolya14@imperial.ac.uk>> wrote: If you want to preserve the symbolic structure of maximum and its dependence on u, then you need neither interpolate nor assign. maximum = 0.5*(u + abs(u)) F = v*(u + maximum)*dx On 15/05/17 10:06, Anna Kalogirou wrote: Hi David, What I would like to do is to define a residual that includes some nonlinear function depending on the unknown, similar to the example with the maximum below (ultimately, I need to use functions abs, exp, tan). I do want to dependence of maximum on u to appear in the definition of the residual somehow; how can I do that then? Thanks, Anna. On 15 May 2017, at 09:44, David Ham <David.Ham@imperial.ac.uk<mailto:David.Ham@imperial.ac.uk>> wrote: On Sun, 14 May 2017 at 21:31 Anna Kalogirou <A.Kalogirou@leeds.ac.uk<mailto:A.Kalogirou@leeds.ac.uk>> wrote: Following up on my previous email, I have found a workaround to those issues, but now I have a problem with the solvers: Traceback (most recent call last): File "/Users/matak/Downloads/Inequality-constraint-Rockafellar/solvers.py", line 32, in solver_F F_problem = NonlinearVariationalProblem(F_solve, w)#, aP=Ap) File "/Users/matak/firedrake/src/firedrake/firedrake/variational_solver.py", line 47, in __init__ raise ValueError("Provided residual is not a linear form") ValueError: Provided residual is not a linear form There two issues here: 1. I cannot give a preconditioning matrix aP -- is this not possible for nonlinear problems? As the documentation for NonlinearVariationalProblem suggests, you can provide Jp, a UFL form for the preconditioning Jacobian. This is the equivalent of aP. 2. I suspect the error above is because I have functions that depend on the solution, and I don’t know if that is acceptable in firedrake. I have something like the following: u = Function(V) v = TestFunction(V) maximum = interpolate(0.5*(u + abs(u)), V) F = v*(u + maximum)*dx Actually, as Colin sort of says, as far as Firedrake is concerned, maximum does not depend on u. This is because doing the interpolation breaks the symbolic link between u and maximum. In the code you have written, maximum does not get updated inside the variational solver as the guess for u gets updated. Whether that is what you wanted to do or not depends on the maths of your problem. The error you are seeing, however, is caused by the Form having two arguments. This almost certainly means you have a TrialFunction in your nonlinear problem, which makes no sense. Regards, David Best wishes, Anna. -- Dr David Ham Department of Mathematics Imperial College London _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake -- Dr David Ham Department of Mathematics Imperial College London _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (2)
- 
                
                Anna Kalogirou
- 
                
                David Ham