Question on mixed solves: RHS is not defined in product function space
Dear firedrakers, assume I want to do the following solve of a mixed system: V1 = FunctionSpace(mesh, 'RT', 1) V2 = FunctionSpace(mesh, 'DG', 0) W = V1 * V2 lmbda = 1 u, p = TrialFunctions(W) v, q = TestFunctions(W) f = Function(V1) g = Function(V2) a = (p*q - q*div(u) + lmbda*inner(v, u) + div(v)*p)*dx L = (dot(u,f)+p*g)*dx u = Function(W) solve(a == L, u, solver_parameters=...) But now I take out the line L = (dot(u,f)+p*g)*dx and assume that somewhere I calculate instead: L1 = dot(TestFunction(V1),f)*dx L2 = TestFunction(V2)*g*dx L1 and L2 taken together contain the same information as L, but I can’t write L=L1+L2, because L1 and L2 were not defined using the mixed function spaces (assume that I calculated L1 and L2 somewhere else in the code, and I only use the mixed function spaces in this subroutine). So given L1 and L2, how can I build L, which can be used in the solve? What I currently do is this: m_u = dot(TestFunction(V1),TrialFunction(V1))*dx m_p = TestFunction(V2)*TrialFunction(V2)*dx f_u = Function(V1) f_p = Function(V2) solve(m_u=L1,f_u) solve(m_p=L2,f_p) L = (dot(u,f_u)+p*f_g)*dx which I believe does the right thing, but it involves mass solves. Is there a better way? Can I copy the data over directly? Thanks a lot, Eike -- Dr Eike Hermann Mueller Research Associate (PostDoc) Department of Mathematical Sciences University of Bath Bath BA2 7AY, United Kingdom +44 1225 38 5803 e.mueller@bath.ac.uk http://people.bath.ac.uk/em459/
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 22/01/15 15:17, Eike Mueller wrote:
Dear firedrakers,
assume I want to do the following solve of a mixed system:
V1 = FunctionSpace(mesh, 'RT', 1) V2 = FunctionSpace(mesh, 'DG', 0)
W = V1 * V2 lmbda = 1 u, p = TrialFunctions(W) v, q = TestFunctions(W) f = Function(V1) g = Function(V2)
a = (p*q - q*div(u) + lmbda*inner(v, u) + div(v)*p)*dx
L = (dot(u,f)+p*g)*dx
u = Function(W) solve(a == L, u, solver_parameters=...)
But now I take out the line
L = (dot(u,f)+p*g)*dx
and assume that somewhere I calculate instead:
L1 = dot(TestFunction(V1),f)*dx L2 = TestFunction(V2)*g*dx
Can you define these two forms using the test functions v and q respectively (rather than building new test functions on the subspaces)? Then everything should "just work". Alternately, if you haven't already assembled L1 and L2, you could (to get L), do: v1 = TestFunction(V1) v2 = TestFunction(V2) L1 = dot(v1, f)*dx L2 = v2*g*dx import ufl L1p = ufl.replace(L1, {v1, v}) L2p = ufl.replace(L2, {v2, v}) L = L1p + L2p but that's effectively the same as just defining L1 and L2 using v and q rather v1 and v2. I guess you're separately using L1 and L2 somewhere in a non-mixed solve? Cheers, Lawrence Cheers, Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQEcBAEBAgAGBQJUwRbFAAoJECOc1kQ8PEYvJHAH/17RtMO14gh60/jIOLFNPxJ0 AkYpR2T44g0oE0/5U2Kw3daLYl3cW1KKi9f5W2FpTy/qmCFL1pJu3qSf1hzIzktT bAdZPm1fxJXychDrZMwT+zPWDJtVHQONvX7ESBnsUmXbFz493J3nktL70DW2ovnM bdS1CDlWEBcqweQG6w7GGI/0bdrf3BYH8o9nt/PCq1Xcl6ItvUiktBwegFlRlaP/ HT0pMPKASdKgtCFqHgLolZW0oiUrnekqDePTz68rzn+FUp2llYwA+YnOFUTcJ0tB x4fbsnh4ktJIg06R3jtqpZFFQuOxwvNVEqALE0FWSjPcpTWVls/VHa/w9PdIBqQ= =tndm -----END PGP SIGNATURE-----
Hi Lawrence, yes, I use the mixed function spaces only in the preconditioner, so I went for your alternative solution. However, now I get: L = ufl.replace(r_p, {TestFunction(self._W3), self._mptest}) \ File "/Users/eikemueller/PostDocBath/EllipticSolvers/ufl/build/lib/ufl/algorithms/replace.py", line 61, in replace mapping2 = dict((k, as_ufl(v)) for (k, v) in iteritems(mapping)) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 484, in iteritems return iter(getattr(d, _iteritems)(**kw)) AttributeError: 'set' object has no attribute ‘iteritems’ Thanks, Eike -- Dr Eike Hermann Mueller Research Associate (PostDoc) Department of Mathematical Sciences University of Bath Bath BA2 7AY, United Kingdom +44 1225 38 5803 e.mueller@bath.ac.uk http://people.bath.ac.uk/em459/
On 22 Jan 2015, at 15:27, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 22/01/15 15:17, Eike Mueller wrote:
Dear firedrakers,
assume I want to do the following solve of a mixed system:
V1 = FunctionSpace(mesh, 'RT', 1) V2 = FunctionSpace(mesh, 'DG', 0)
W = V1 * V2 lmbda = 1 u, p = TrialFunctions(W) v, q = TestFunctions(W) f = Function(V1) g = Function(V2)
a = (p*q - q*div(u) + lmbda*inner(v, u) + div(v)*p)*dx
L = (dot(u,f)+p*g)*dx
u = Function(W) solve(a == L, u, solver_parameters=...)
But now I take out the line
L = (dot(u,f)+p*g)*dx
and assume that somewhere I calculate instead:
L1 = dot(TestFunction(V1),f)*dx L2 = TestFunction(V2)*g*dx
Can you define these two forms using the test functions v and q respectively (rather than building new test functions on the subspaces)? Then everything should "just work".
Alternately, if you haven't already assembled L1 and L2, you could (to get L), do:
v1 = TestFunction(V1) v2 = TestFunction(V2)
L1 = dot(v1, f)*dx L2 = v2*g*dx
import ufl L1p = ufl.replace(L1, {v1, v}) L2p = ufl.replace(L2, {v2, v})
L = L1p + L2p
but that's effectively the same as just defining L1 and L2 using v and q rather v1 and v2. I guess you're separately using L1 and L2 somewhere in a non-mixed solve?
Cheers,
Lawrence
Cheers,
Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ <http://www.enigmail.net/>
iQEcBAEBAgAGBQJUwRbFAAoJECOc1kQ8PEYvJHAH/17RtMO14gh60/jIOLFNPxJ0 AkYpR2T44g0oE0/5U2Kw3daLYl3cW1KKi9f5W2FpTy/qmCFL1pJu3qSf1hzIzktT bAdZPm1fxJXychDrZMwT+zPWDJtVHQONvX7ESBnsUmXbFz493J3nktL70DW2ovnM bdS1CDlWEBcqweQG6w7GGI/0bdrf3BYH8o9nt/PCq1Xcl6ItvUiktBwegFlRlaP/ HT0pMPKASdKgtCFqHgLolZW0oiUrnekqDePTz68rzn+FUp2llYwA+YnOFUTcJ0tB x4fbsnh4ktJIg06R3jtqpZFFQuOxwvNVEqALE0FWSjPcpTWVls/VHa/w9PdIBqQ= =tndm -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake <https://mailman.ic.ac.uk/mailman/listinfo/firedrake>
Arrgh, stupid me, the argument should be a dict: {v, v1} -> {v: v1}. But it still complains that it can’t add expressions of different shapes. -- Dr Eike Hermann Mueller Research Associate (PostDoc) Department of Mathematical Sciences University of Bath Bath BA2 7AY, United Kingdom +44 1225 38 5803 e.mueller@bath.ac.uk http://people.bath.ac.uk/em459/
On 22 Jan 2015, at 15:38, Eike Mueller <E.Mueller@bath.ac.uk> wrote:
Hi Lawrence,
yes, I use the mixed function spaces only in the preconditioner, so I went for your alternative solution. However, now I get:
L = ufl.replace(r_p, {TestFunction(self._W3), self._mptest}) \ File "/Users/eikemueller/PostDocBath/EllipticSolvers/ufl/build/lib/ufl/algorithms/replace.py", line 61, in replace mapping2 = dict((k, as_ufl(v)) for (k, v) in iteritems(mapping)) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 484, in iteritems return iter(getattr(d, _iteritems)(**kw)) AttributeError: 'set' object has no attribute ‘iteritems’
Thanks,
Eike
--
Dr Eike Hermann Mueller Research Associate (PostDoc)
Department of Mathematical Sciences University of Bath Bath BA2 7AY, United Kingdom
+44 1225 38 5803 e.mueller@bath.ac.uk <mailto:e.mueller@bath.ac.uk> http://people.bath.ac.uk/em459/
On 22 Jan 2015, at 15:27, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk <mailto:lawrence.mitchell@imperial.ac.uk>> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 22/01/15 15:17, Eike Mueller wrote:
Dear firedrakers,
assume I want to do the following solve of a mixed system:
V1 = FunctionSpace(mesh, 'RT', 1) V2 = FunctionSpace(mesh, 'DG', 0)
W = V1 * V2 lmbda = 1 u, p = TrialFunctions(W) v, q = TestFunctions(W) f = Function(V1) g = Function(V2)
a = (p*q - q*div(u) + lmbda*inner(v, u) + div(v)*p)*dx
L = (dot(u,f)+p*g)*dx
u = Function(W) solve(a == L, u, solver_parameters=...)
But now I take out the line
L = (dot(u,f)+p*g)*dx
and assume that somewhere I calculate instead:
L1 = dot(TestFunction(V1),f)*dx L2 = TestFunction(V2)*g*dx
Can you define these two forms using the test functions v and q respectively (rather than building new test functions on the subspaces)? Then everything should "just work".
Alternately, if you haven't already assembled L1 and L2, you could (to get L), do:
v1 = TestFunction(V1) v2 = TestFunction(V2)
L1 = dot(v1, f)*dx L2 = v2*g*dx
import ufl L1p = ufl.replace(L1, {v1, v}) L2p = ufl.replace(L2, {v2, v})
L = L1p + L2p
but that's effectively the same as just defining L1 and L2 using v and q rather v1 and v2. I guess you're separately using L1 and L2 somewhere in a non-mixed solve?
Cheers,
Lawrence
Cheers,
Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ <http://www.enigmail.net/>
iQEcBAEBAgAGBQJUwRbFAAoJECOc1kQ8PEYvJHAH/17RtMO14gh60/jIOLFNPxJ0 AkYpR2T44g0oE0/5U2Kw3daLYl3cW1KKi9f5W2FpTy/qmCFL1pJu3qSf1hzIzktT bAdZPm1fxJXychDrZMwT+zPWDJtVHQONvX7ESBnsUmXbFz493J3nktL70DW2ovnM bdS1CDlWEBcqweQG6w7GGI/0bdrf3BYH8o9nt/PCq1Xcl6ItvUiktBwegFlRlaP/ HT0pMPKASdKgtCFqHgLolZW0oiUrnekqDePTz68rzn+FUp2llYwA+YnOFUTcJ0tB x4fbsnh4ktJIg06R3jtqpZFFQuOxwvNVEqALE0FWSjPcpTWVls/VHa/w9PdIBqQ= =tndm -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake <https://mailman.ic.ac.uk/mailman/listinfo/firedrake>
firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 22/01/15 15:41, Eike Mueller wrote:
Arrgh, stupid me, the argument should be a dict: {v, v1} -> {v: v1}. But it still complains that it can?t add expressions of different shapes.
Hmm, odd, I do the following, which works afaict: from firedrake import * m = UnitIcosahedralSphereMesh(0) m.init_cell_orientations(Expression(("x[0]", "x[1]", "x[2]"))) RT = FunctionSpace(m, 'RT', 1) DG = FunctionSpace(m, 'DG', 0) W = RT*DG f = Function(RT) g = Function(DG) f.assign(1) g.assign(2) v, q = TestFunctions(W) v1 = TestFunction(RT) q1 = TestFunction(DG) import ufl print assemble(dot(f, v)*dx + g*q*dx).dat.data L1 = ufl.replace(dot(f, v1)*dx, {v1: v}) L2 = ufl.replace(g*q1*dx, {q1: q}) print assemble(L1 + L2).dat.data Cheers, Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQEcBAEBAgAGBQJUwR1pAAoJECOc1kQ8PEYvp7wIAIdQNrcPJ/Q8xoVO4BVuXjkU nD1ft85Hb6prZ32NJQ549dqFTYhxKCkJWRrswkwaUewAL4PUmv2mywdV2igfGsxH NWursvetXc7IBlcFLJWB7bxKlTPUM4hEy2lVofVVr8tFrQjDWjU5dFQ3P+bOfx8i xPep8vlUbAzQbkzEPAsEZarFZZ6gYVGDRFJYxtm+bQR0zynxcF1RDq/XF3+lmEcZ yeXoed//+7bb2pCpCCMUD3LkSD3vK3FXyacbQf44E3EcLi6HDCxZoH+sD7ad74eV 1ay2J6MwHwBvmOaDKU2T0P7YgRPbDfjcnHIDvQah3hJkJxnBL7agPeAYdSGAUQ0= =vCrZ -----END PGP SIGNATURE-----
participants (2)
- 
                
                Eike Mueller
- 
                
                Lawrence Mitchell