Split forms on mixed function spaces - #194
Conversation
There was a problem hiding this comment.
Do we really want to unconditionally silence FFC?
There was a problem hiding this comment.
This is what we used to do in PyOP2, but maybe not.
There was a problem hiding this comment.
In fact, it's more complicated than that right. It's a list of block indices and kernels, yes?
There was a problem hiding this comment.
True, that docstring needs updating.
|
This doesn't work for problems cast in nonlinear form: from firedrake import *
mesh = UnitSquareMesh(2, 2)
V1 = FunctionSpace(mesh, "BDM", 1, name="V")
V2 = FunctionSpace(mesh, "DG", 0, name="P")
W = V1 * V2
# Define variational problem
lmbda = 1
x = Function(W)
u, p = TrialFunctions(W)
v, q = TestFunctions(W)
f = Function(V2)
f.interpolate(Expression("(1+8*pi*pi)*sin(x[0]*pi*2)*sin(x[1]*pi*2)"))
F = (p*q - q*div(u) + lmbda*inner(v, u) + div(v)*p) * dx - f*q*dx
a = lhs(F)
L = rhs(F)
F = action(a, x) - L
solve(F == 0, x)Results in: |
|
@wence- I have fixed that case and added the test you were running. The form splitter wasn't correctly dealing with the case of renumbered arguments. |
|
Thanks, here's another one: from firedrake import *
mesh = UnitSquareMesh(2, 2)
V1 = FunctionSpace(mesh, "BDM", 1, name="V")
V2 = FunctionSpace(mesh, "DG", 0, name="P")
W = V1 * V2
# Define variational problem
lmbda = 1
x = Function(W)
u, p = split(x)
v, q = TestFunctions(W)
F = (inner(u, v) + v[1]*p)*dx
assemble(derivative(F, x)) |
|
This is simplified from Colin's Skamarock-Klemp model. |
|
@wence- You need this UFL branch (which still waits on review): https://bitbucket.org/mapdes/ufl/pull-request/8/simplification-rules-required-for-form/ What is happening is that UFL doesn't detect that the first block of this form is effectively 0. This form is then fed to FFC, which does some more analysis and ends up with no terms in its IR. @FabioLuporini's PyOP2 IR currently chokes on this with this rather unhelpful error. I've added some simplification rules to make UFL detect common cases of "empty" blocks so that we're not even passing those on to FFC. |
|
Is this now good to go? |
|
Why did this pass tests? It's not rebased on master, so it doesn't have Lawrence's updated facet tests in. The old test should be failing, now that the FFC fix is in. |
|
@dorugeber Travis tests the result of the pull request i.e. this branch merged with master. |
|
Thanks for clarifying that. I assume this branch is fine, but Doru and I had some strange behaviour when we rebased our facet branch on this. (Rebasing on this was our solution to the integral ordering mismatch, and we found an unexpected extra argument was being passed into the kernel) It shouldn't block this PR from going ahead, assuming everything works at the moment, but we'll probably be asking you for advice in the next couple of days. |
Does not work with disk caching for now since Coefficients can't be serialised.
Adapt to changes in compile_form, which now returns a four-tuple of index, domain type, coefficients and kernel. We now need to pull apart the tensor and test and trial functions if it is a mixed type and extract the component for the block the kernel contributes to and filter the boundary conditions to only include those defined on the current block.
FFCKernel goes back to handling only a single kernel on a single integral.
Instead of making one pass over the form and getting back a list of subforms on the blocks of the mixed space, make as many passes as there are blocks in the mixed space and only enabling one component of each Argument at a time. When splitting an Argument, create a UFL ListTensor where only the component of the MixedFunctionSpace selected by the current block index is included and all other components are set to Zero. These Zeros are subsequently eliminated as they are used in expressions and not propagated up the form tree.
When building integral_data for the form_data object, the domain_data which Firedrake uses to carry the coordinate field is stripped. We therefore need to get the integrals with intact integral_data via the preprocessed form.
|
Can this finally land? The Travis failure is unrelated as you can tell and it passes on buildbot. |
Split forms on mixed function spaces
When passing a form to the ffc_interface, the form's arguments are
split and a form per block in the mixed space is returned.