← Back to team overview

ufl team mailing list archive

Re: [Question #215432]: True User-defined Operators for UFL

 

Question #215432 on UFL changed:
https://answers.launchpad.net/ufl/+question/215432

    Status: Open => Answered

Martin Sandve Alnæs proposed the following answer:
I'm not quite sure what you're asking for here, but I'll try to point
you in the right direction. Are you aware of the distinction between UFL
and DOLFIN? You will have to evaluate your external code and its
derivatives behind the appropriate DOLFIN interfaces, and use
placeholder functions for the results in UFL.

The tricky part is not evaluate the nonlinear coefficient field, that
you can just implement in C++ behind dolfin interfaces, but the
linearization. What is your linearization strategy? You don't specify
what kind of derivatives you can get for p(c). If you can compute

s: Omega -> R
s = \frac{\partial p(c)}{\partial c}

then you can implement the derivative of your weak form as

c = Coefficient(V)
s = Coefficient(V) # represents s = dp/dc
q = Coefficient(V) # represents q = p(c)
ct = TrialFunction(V)
v = TestFunction(V)
a = s*ct*dot(grad(c), grad(v))*dx + q*dot(grad(ct), grad(v))*dx

(not verified, so don't trust this!)

To use the Newton solver in dolfin, you need to implement the NonlinearProblem as in this example:
http://fenicsproject.org/documentation/dolfin/1.0.0/cpp/demo/pde/cahn-hilliard/cpp/documentation.html
and remember to update q = p(c) and s = dp/dc before each assemble.

-- 
You received this question notification because you are a member of UFL
Team, which is an answer contact for UFL.