This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Norm of residuum

+1 vote

Hi,
I have a nonlinear problem defined in the following way

    self.mesh = dolfin.Mesh(meshXML);
    V = FunctionSpace(self.mesh, 'Lagrange', self.lagrangeSpaceDim)
    bc = boundary_definition()
    du = TrialFunction(V)
    u_ = Function(V)     # most recently computed solution
    u_ = self.solveLinearOn(V, bc)#interpolate(Expression("x[0]"), V)
    #could not call u_ = self.solveLinear(meshXML, lagrangeSpaceDim) this problem described here
    #http://fenicsproject.org/qa/3537/mesh-xml-inconsistent-import
    v  = TestFunction(V)
    F  = inner(self.psi(sqrt(2)*sqrt(inner(nabla_grad(u_), nabla_grad(u_))))*nabla_grad(u_), nabla_grad(v))*dx
    J  = derivative(F, u_, du)  # Gateaux derivative in dir. of du

    #could not do problem = NonlinearVariationalProblem(F, u_, bc.fullBC(V), J) probably due to pointer misimplementation
    bcs = bc.fullBC(V)
    problem = NonlinearVariationalProblem(F, u_, bcs, J)

so that u_ is a initial guess solution. Then I basically call

solver  = NonlinearVariationalSolver(problem)
solver.solve()
return(u_)

I would like for particular object u_ (which I import from elsewhere or solve by another program) to know residual norm of the F. So basically norm of the vector of F applied on each test function, which is called residual norm. Is there some way to do that?

I found that NonlinearVariationalProblem has member residual_form(). But I do not know how extract the information about its particullar value for the set of test functions.

asked May 17, 2014 by kulvv1am FEniCS Novice (270 points)
edited May 17, 2014 by kulvv1am

1 Answer

+1 vote
 
Best answer

Have you tried to assemble F? I was successful doing that once, but I am afraid I deleted the code and do not recall exactly how I did it. I do know you have to be careful applying the boundary conditions.

answered May 18, 2014 by mike125 FEniCS Novice (670 points)
selected May 26, 2014 by kulvv1am

Thank you. For me worked this pseudo code which I am posting here for inspiration. I figured out finally how to get rid of Dirichlet boundary conditions data.

bcs = bc.fullBC(V)
problem = NonlinearVariationalProblem(F, u_, bcs, J)
x = problem.residual_form()
indicators = assemble(x)
if type(bcs) is list:
    for i in range(0, len(bcs)):
        bcs[i].apply(indicators, u_.vector())#hack for Dirichlet boundary conditions
    else:
        bcs.apply(indicators, u_.vector())
error = numpy.linalg.norm(indicators.array())
plot(Function(V, indicators))
...