Non-Linear Coeffecients: dependent on trial functions;

I have tried today another way to evaluate the coefficient function U(pf) that is dependent on the trial function p.

I tried to ensure that the return value into the weak form is of the form UFL. In the coefficient function definition I looped on the vertex values of the trial function p (using p.compute_vertex_values()) and within each loop I evaluated the expression that I need (integration of a function in my case) and then assigned the computed value to a corresponding vertex value of the coefficient function which was apriori defined as a function(maybe I should try as a trial function) of the mesh domain similar to the actual trial function p. This seems to be logical and intuitive but doesn’t seem to work as such for a non-linear problem. However, this kind of function evaluation by looping seems to work if loop over the vertex values of a previous solution (i.e. a function of instead of a trial function like p). So end of the day I probably have to resort to some kind of iterative approach (Picard or Newton) or approximate that my coefficients need to be evaluated from a previous know solution. Nevertheless, please see what I have done and the corresponding error in the case of direct non-linear approach.

Q       = FunctionSpace(mesh,'P',1)
Uf  = Function(Q)
def U(pf):
    coordinates = mesh.coordinates()
    vertex_values_p = pf.compute_vertex_values()
    vertex_values_U = Uf.compute_vertex_values()
    for i,x in enumerate(coordinates):
        z = sympy.Symbol("z")
        vertex_values_U[i] = sympy.integrate((((-z)^(1/2)+1)^-1),(z,0,vertex_values_p[i])) - vertex_values_p[i]*(((-vertex_values_p[i]/M)**(1/pm)+1)**-1)
    return Uf

The error is as below when evaluating the function call:

215     coordinates = mesh.coordinates()
--> 216     vertex_values_p = pf.compute_vertex_values()
217     vertex_values_U = Uf.compute_vertex_values()

AttributeError: 'Indexed' object has no attribute 'compute_vertex_values'
fenics@2bc3e4917bf0:~/shared$ 

Basically it says that the when I pass the trial function as an argument (nonlinear case) it says that there exist no attribute called vertex values but when I do the same by passing a function (previous solution in linear case) it extracts nicely the vertex values.

The weird part is in my original post the error due to Coefficient function S(pf) was because I recalled it in the U(pf). As such S(pf) does not seem to have any problem even if I try to evaluate it in a non linear case using trial function p. Only U(pf) seems to have this issue. I understood this when I stopped calling S(pf) in U(pf) and instead directly used the function expression of S(pf) and additional thing I did was a definite integration. I believe the problem lies in this additional integration.

Any ideas would be appreciated.

many Thanks,
Sid