Re: [firedrake] Solver error -- Provided residual is not a linear form
Okay, I'm not sure what's going on here, so I'll leave this for someone else. I suspect that one of those variables is "not what you think it is", i.e. not a UFL object. Perhaps you accidentally overwrote a variable, or just set it to the wrong object? The original error message turns out to be misleading. Apparently the as_ufl call in ufl/constantvalue.py is failing, which is the real error. In trying to generate an error message for that, it tries to generate a string representation of the expression, which also failed, producing the error that you reported. Full traceback: (firedrake) andrew@ubuntu:~/anna/buoy2d/Inequality-constraint-Rockafellar$ python buoy-swe.py UFL:ERROR UFL conditions cannot be evaluated as bool in a Python context. Traceback (most recent call last): File "buoy-swe.py", line 82, in <module> F_solver = solver_F(phi0_5, h1, lambda0_5, Z1, W0_5, I, w, phi0, h0, Z0, W0, phi_t, h_t, lambda_t, Z_t, W_t, I_t, v1, v2, v3, v4, v5, v6, dt, Hx, H0, L, dR_dt, g, rho, Mass, H, a, r, coords.dat.data, solvers_print); File "/home/andrew/anna/buoy2d/Inequality-constraint-Rockafellar/solvers.py", line 25, in solver_F + 0.5*((lambda0_5 + exp(r*(h0-(Z0 - H - tan(a)*(x-L)))) - 1) + abs(lambda0_5 + exp(r*(h0-(Z0 - H - tan(a)*(x-L)))) - 1))*exp(r*(h0-(Z0 - H - tan(a)*(x-L)))) )*dx File "/home/andrew/firedrake/src/ufl/ufl/operators.py", line 584, in exp return _mathfunction(f, Exp) File "/home/andrew/firedrake/src/ufl/ufl/operators.py", line 570, in _mathfunction f = as_ufl(f) File "/home/andrew/firedrake/src/ufl/ufl/constantvalue.py", line 417, in as_ufl " to any UFL type." % str(expression)) File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/numeric.py", line 1961, in array_str return array2string(a, max_line_width, precision, suppress_small, ' ', "", str) File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/arrayprint.py", line 463, in array2string separator, prefix, formatter=formatter) File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/arrayprint.py", line 327, in _array2string suppress_small, formatter) File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/arrayprint.py", line 290, in _get_format_function formatdict = _get_formatdict(data, precision, suppress_small, formatter) File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/arrayprint.py", line 239, in _get_formatdict 'int': IntegerFormat(data), File "/home/andrew/firedrake/local/lib/python2.7/site-packages/numpy/core/arrayprint.py", line 654, in __init__ max_str_len = max(len(str(maximum.reduce(data))), File "/home/andrew/firedrake/src/ufl/ufl/conditional.py", line 46, in __bool__ error("UFL conditions cannot be evaluated as bool in a Python context.") File "/home/andrew/firedrake/src/ufl/ufl/log.py", line 172, in error raise self._exception_type(self._format_raw(*message)) ufl.log.UFLException: UFL conditions cannot be evaluated as bool in a Python context. On 15 May 2017 at 10:35, Anna Kalogirou <A.Kalogirou@leeds.ac.uk> wrote:
The full code can be found here: https://bitbucket.org/annakalog/buoy2d/src/7a99dc59b9d1ddd90105d1313c83ee a71baafda4/Inequality-constraint-Rockafellar/?at=master Please make sure to go to the right folder, i.e. Buoy2D <https://bitbucket.org/annakalog/buoy2d/src/7a99dc59b9d1?at=master> / Inequality-constraint-Rockafellar /
Thanks,
Anna.
On 15 May 2017, at 10:13, Andrew McRae <A.T.T.McRae@bath.ac.uk> wrote:
Unless I'm being dumb, this really should work as you've written it (using assign/interpolate definitely *won't* do what you want).
Can you send a fuller version of your code as I suspect the error is caused by something else?
Andrew
On 15 May 2017 at 09:48, Anna Kalogirou <A.Kalogirou@leeds.ac.uk> wrote:
Hi Colin,
Thanks, indeed I had forgotten a trial function in my residual.
Yes I do need the the u-dependence in the maximum during the solve. If I substitute the definition of maximum into the residual, i.e. write F = v*(u + 0.5*(u + abs(u)))*dx gives the error ufl.log.UFLException: UFL conditions cannot be evaluated as bool in a Python context.
Will it work if I use assign instead of interpolate?
Best, Anna.
On 15 May 2017, at 07:59, Colin Cotter <colin.cotter@imperial.ac.uk> wrote:
Hi Anna, Are you intending that the u-dependence in maximum should be maintained during the solve? After doing the interpolation, there will be no symbolic record of where maximum's values came from.
That's probably not the cause of the error message though. It says that the form is not a linear form. This might mean that you accidentally included some TrialFunction (which turns it into a bilinear form) or perhaps forgot a factor of dx or dS somewhere (which stops it from being a form).
all the best --cjc
On 14 May 2017 at 21:30, 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? 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
Best wishes,
Anna.
-- http://www.imperial.ac.uk/people/colin.cotter
www.cambridge.org/9781107663916
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (1)
- 
                
                Andrew McRae