Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I assemble the (dense, rectangular) Jacobian of a side constraint? #1263

Open
pefarrell opened this issue Aug 14, 2018 · 1 comment

Comments

@pefarrell
Copy link
Contributor

(Possibly not a bug/user error)

I'm trying to assemble the Jacobian of a side constraint in a PDE-constrained optimisation problem. The constraint is that u*dx == V. I test this equation with a TestFunction from FunctionSpace(mesh, "R", 0). However, when I take its Jacobian and try to assemble it, I can't seem to get an explicit PETSc matrix out. (I intend to pass the assembled Jacobian to IPOPT.)

Consider the following code:

from firedrake import *

mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, "CG", 1)
R = FunctionSpace(mesh, "R", 0)
v = TestFunction(R)
u = TrialFunction(V)

form = inner(u, v)*dx
J = assemble(form, mat_type="aij")
J.force_evaluation()
print(J.petscmat.type)

I was expecting it to print "aij", but instead it prints "python". How can I get the matrix entries out? (mat_type="dense" isn't recognised.)

@dham
Copy link
Member

dham commented Aug 16, 2018

The rectangular blocks produced by the "R" space are represented as PyOP2 dats wrapped in PETSc Python matrices. I think J.petscmat.getPythonContext().dat will give you the entries which live on this process. This possibly should be done with a PETSc dense matrix. At the time, I didn't know such things existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants