Re: [firedrake] Solve multiple variational problems at once
Actually, assuming the original problems were written so that v is in the same space as u1, which is how I read the spec, then this is ill-posed. Instead you need to pull the test function from the mixed space too. W = MixedFunctionSpace(...) w = Function(W) v = TestFunction(W) u1, u2, u3 = split(w) v1, v2, v3 = split(v) F = fn(u1, u2, u3; v1) etc... solve(F + G + H == 0, w) On 26 November 2014 at 10:28, Mitchell, Lawrence < lawrence.mitchell@imperial.ac.uk> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 26/11/14 10:19, Anna Kalogirou wrote:
Dear all,
How would I solve multiple nonlinear variational problems simultaneously? For example, say that I have three residuals
F(u1,u2,u3;v) = 0 G(u1,u2,u3;v) = 0 H(u1,u2,u3;v) = 0,
where v is the test function. I need to solve all three of them together. Any suggestions?
Assuming you have:
W = MixedFunctionSpace(...)
w = Function(W)
u1, u2, u3 = split(w)
F = fn(u1, u2, u3; v) etc...
Since you're linear in v, can you not just write:
solve(F + G + H == 0, w)
?
Or am I missing something?
Lawrence
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/
iQEcBAEBAgAGBQJUdas2AAoJECOc1kQ8PEYvGzIIAM/PQ/7o82RvhWC2StXETQtm ub5cvB+sj6ceqyE73L4bJzMjNvqdjSMy61QcCErho6nyeviqtvCDKbih98Sy7tut 7QMKLFQgwB1JdtnmdU4Rc5cm6pDDo2LPE07pbHmRSAl7XUH0GZTcqRAJoBubEzcn BxcF0vRAgr++Y+4ak+Snt2k950k2mf3jE4Q3oA/KpkL8nVfEkBWU5ACb23CbKLAD lO5ZrOFuSYHoyj+Fcn8aEsrBGHEDwv6GhNoyWqo46speLCEamJN1E5D7KxYXuTCj W5lNHMPM0VeWvEiH69j4CidRbCo5Mba7rwVYJMzDWiXa0/avuFDlq2oOzxmIIIs= =BZY9 -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr David Ham Departments of Mathematics and Computing Imperial College London http://www.imperial.ac.uk/people/david.ham
Thank you both very much. I am trying to implement it now. Anna. On 26/11/14 11:12, David Ham wrote:
Actually, assuming the original problems were written so that v is in the same space as u1, which is how I read the spec, then this is ill-posed. Instead you need to pull the test function from the mixed space too.
W = MixedFunctionSpace(...)
w = Function(W) v = TestFunction(W)
u1, u2, u3 = split(w) v1, v2, v3 = split(v)
F = fn(u1, u2, u3; v1) etc...
solve(F + G + H == 0, w)
On 26 November 2014 at 10:28, Mitchell, Lawrence <lawrence.mitchell@imperial.ac.uk <mailto:lawrence.mitchell@imperial.ac.uk>> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 26/11/14 10:19, Anna Kalogirou wrote: > Dear all, > > How would I solve multiple nonlinear variational problems > simultaneously? For example, say that I have three residuals > > F(u1,u2,u3;v) = 0 G(u1,u2,u3;v) = 0 H(u1,u2,u3;v) = 0, > > where v is the test function. I need to solve all three of them > together. Any suggestions?
Assuming you have:
W = MixedFunctionSpace(...)
w = Function(W)
u1, u2, u3 = split(w)
F = fn(u1, u2, u3; v) etc...
Since you're linear in v, can you not just write:
solve(F + G + H == 0, w)
?
Or am I missing something?
Lawrence
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/
iQEcBAEBAgAGBQJUdas2AAoJECOc1kQ8PEYvGzIIAM/PQ/7o82RvhWC2StXETQtm ub5cvB+sj6ceqyE73L4bJzMjNvqdjSMy61QcCErho6nyeviqtvCDKbih98Sy7tut 7QMKLFQgwB1JdtnmdU4Rc5cm6pDDo2LPE07pbHmRSAl7XUH0GZTcqRAJoBubEzcn BxcF0vRAgr++Y+4ak+Snt2k950k2mf3jE4Q3oA/KpkL8nVfEkBWU5ACb23CbKLAD lO5ZrOFuSYHoyj+Fcn8aEsrBGHEDwv6GhNoyWqo46speLCEamJN1E5D7KxYXuTCj W5lNHMPM0VeWvEiH69j4CidRbCo5Mba7rwVYJMzDWiXa0/avuFDlq2oOzxmIIIs= =BZY9 -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr David Ham Departments of Mathematics and Computing Imperial College London
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
Do I still need to define u1, u2, u3 = Functions(V), where V is in original space? After the variational problem is solved I split w as u1, u2, u3 = split(w) and try to print u1, u2, u3 in files, but I get AttributeError: 'Indexed' object has no attribute 'function_space'. Also, I can't interpolate or assign. In the end, I want to pass u1, u2, u3 to some other functions u1_, u2_, u3_, which also appear in the residual expressions. But this produces a 'Mismatching function spaces' error. On 26/11/14 11:12, David Ham wrote:
Actually, assuming the original problems were written so that v is in the same space as u1, which is how I read the spec, then this is ill-posed. Instead you need to pull the test function from the mixed space too.
W = MixedFunctionSpace(...)
w = Function(W) v = TestFunction(W)
u1, u2, u3 = split(w) v1, v2, v3 = split(v)
F = fn(u1, u2, u3; v1) etc...
solve(F + G + H == 0, w)
On 26 November 2014 at 10:28, Mitchell, Lawrence <lawrence.mitchell@imperial.ac.uk <mailto:lawrence.mitchell@imperial.ac.uk>> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 26/11/14 10:19, Anna Kalogirou wrote: > Dear all, > > How would I solve multiple nonlinear variational problems > simultaneously? For example, say that I have three residuals > > F(u1,u2,u3;v) = 0 G(u1,u2,u3;v) = 0 H(u1,u2,u3;v) = 0, > > where v is the test function. I need to solve all three of them > together. Any suggestions?
Assuming you have:
W = MixedFunctionSpace(...)
w = Function(W)
u1, u2, u3 = split(w)
F = fn(u1, u2, u3; v) etc...
Since you're linear in v, can you not just write:
solve(F + G + H == 0, w)
?
Or am I missing something?
Lawrence
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/
iQEcBAEBAgAGBQJUdas2AAoJECOc1kQ8PEYvGzIIAM/PQ/7o82RvhWC2StXETQtm ub5cvB+sj6ceqyE73L4bJzMjNvqdjSMy61QcCErho6nyeviqtvCDKbih98Sy7tut 7QMKLFQgwB1JdtnmdU4Rc5cm6pDDo2LPE07pbHmRSAl7XUH0GZTcqRAJoBubEzcn BxcF0vRAgr++Y+4ak+Snt2k950k2mf3jE4Q3oA/KpkL8nVfEkBWU5ACb23CbKLAD lO5ZrOFuSYHoyj+Fcn8aEsrBGHEDwv6GhNoyWqo46speLCEamJN1E5D7KxYXuTCj W5lNHMPM0VeWvEiH69j4CidRbCo5Mba7rwVYJMzDWiXa0/avuFDlq2oOzxmIIIs= =BZY9 -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr David Ham Departments of Mathematics and Computing Imperial College London
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 26/11/14 12:24, Anna Kalogirou wrote:
Do I still need to define u1, u2, u3 = Functions(V), where V is in original space? After the variational problem is solved I split w as
u1, u2, u3 = split(w)
and try to print u1, u2, u3 in files, but I get
AttributeError: 'Indexed' object has no attribute 'function_space'.
Aha, you run into the split(w) vs. w.split() problem. When you're defining your variational form, you need to use the former. For output purposes (and assignment in a timestepping loop) you need to use the latter. e.g. u1, u2 = split(w) F = fn(u1, u2; v) u1, u2 = w.split() solve(F == 0, w) u1_.assign(u1) u2_.assign(u2) etc...
Also, I can't interpolate or assign. In the end, I want to pass u1, u2, u3 to some other functions u1_, u2_, u3_, which also appear in the residual expressions. But this produces a 'Mismatching function spaces' error.
I hope the above should also clear up this problem. Cheers, Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQEcBAEBAgAGBQJUdcteAAoJECOc1kQ8PEYv9FMIANxK3tJWLEHrK/mrd3zqWKFK C1pb9+IFoEENBX1kwlTjor8sOZjpK4i/jyMVyVLl+zML47rnTYLsY0uMBf8reuT0 72JjLo5C5+TEgXA3mHq0YE6Ohw/7ls38moJaE0LYKiTqZQ2xfsjH7VCTe4a4vXlo Kw0JIeiWPvq5SAhPRpv3xl4MYfFtpNtg9Qat+B8S9HJNzQeY1bEmSP9U8xzkcouT hOpg2FKseroIWK9CefCJgqF4Pa9vL8S5Hz3FWkt1QAJHS68+q8qSqxsMxLamrFZS E5uwqAqZMU02CTBSGtEKXqljEDoqd+XKGEEX6uq6qzFlrpmxEM6zXBVZC7+ofWU= =oHan -----END PGP SIGNATURE-----
That is what is am doing and it still complains about Mismatching Function Spaces.. So what I have now is, let's say u1_ = Function(V) u2_ = Function(V) w = Function(W), where W = V*V v = TestFunction(W) u1, u2 = split(w) v1, v2 = split(v) *Here I also tried defining instead v1, v2 = TestFunctions(W).* F = fn(u1, u2, u1_, u2_; v1) G = fn(u1, u2, u1_, u2_; v2) u1, u2 = w.split() *OR does this need to be after the variational problem is solved?* *I tried both with the same outcome.* solve(F == 0, w) u1_.assign(u1) u2_.assign(u2). On 26/11/14 12:45, Lawrence Mitchell wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 26/11/14 12:24, Anna Kalogirou wrote:
Do I still need to define u1, u2, u3 = Functions(V), where V is in original space? After the variational problem is solved I split w as
u1, u2, u3 = split(w)
and try to print u1, u2, u3 in files, but I get
AttributeError: 'Indexed' object has no attribute 'function_space'. Aha, you run into the split(w) vs. w.split() problem.
When you're defining your variational form, you need to use the former. For output purposes (and assignment in a timestepping loop) you need to use the latter.
e.g.
u1, u2 = split(w)
F = fn(u1, u2; v)
u1, u2 = w.split()
solve(F == 0, w)
u1_.assign(u1) u2_.assign(u2)
etc...
Also, I can't interpolate or assign. In the end, I want to pass u1, u2, u3 to some other functions u1_, u2_, u3_, which also appear in the residual expressions. But this produces a 'Mismatching function spaces' error. I hope the above should also clear up this problem.
Cheers,
Lawrence -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/
iQEcBAEBAgAGBQJUdcteAAoJECOc1kQ8PEYv9FMIANxK3tJWLEHrK/mrd3zqWKFK C1pb9+IFoEENBX1kwlTjor8sOZjpK4i/jyMVyVLl+zML47rnTYLsY0uMBf8reuT0 72JjLo5C5+TEgXA3mHq0YE6Ohw/7ls38moJaE0LYKiTqZQ2xfsjH7VCTe4a4vXlo Kw0JIeiWPvq5SAhPRpv3xl4MYfFtpNtg9Qat+B8S9HJNzQeY1bEmSP9U8xzkcouT hOpg2FKseroIWK9CefCJgqF4Pa9vL8S5Hz3FWkt1QAJHS68+q8qSqxsMxLamrFZS E5uwqAqZMU02CTBSGtEKXqljEDoqd+XKGEEX6uq6qzFlrpmxEM6zXBVZC7+ofWU= =oHan -----END PGP SIGNATURE-----
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Dr Anna Kalogirou Research Fellow School of Mathematics University of Leeds
Hi Anna, On 26 Nov 2014, at 14:19, Anna Kalogirou <a.kalogirou@leeds.ac.uk> wrote:
That is what is am doing and it still complains about Mismatching Function Spaces.. So what I have now is, let's say
u1_ = Function(V) u2_ = Function(V) w = Function(W), where W = V*V v = TestFunction(W)
u1, u2 = split(w) v1, v2 = split(v) *Here I also tried defining instead v1, v2 = TestFunctions(W).*
F = fn(u1, u2, u1_, u2_; v1) G = fn(u1, u2, u1_, u2_; v2)
u1, u2 = w.split() *OR does this need to be after the variational problem is solved?* *I tried both with the same outcome.*
solve(F == 0, w)
u1_.assign(u1) u2_.assign(u2).
I see. It turns out support for this option is currently unimplemented in the expression assembler (used for assignment here). However, it should be possible, because the functionspaces all match. The code change to allow this was quite small, so I did so. It is currently waiting on code review but should hopefully be in firedrake master soon: you can see the changes here https://github.com/firedrakeproject/firedrake/pull/400. Cheers, Lawrence
On 26 Nov 2014, at 15:18, Lawrence Mitchell <lawrence.mitchell@imperial.ac.uk> wrote:
Hi Anna,
On 26 Nov 2014, at 14:19, Anna Kalogirou <a.kalogirou@leeds.ac.uk> wrote:
That is what is am doing and it still complains about Mismatching Function Spaces.. So what I have now is, let's say
u1_ = Function(V) u2_ = Function(V) w = Function(W), where W = V*V v = TestFunction(W)
u1, u2 = split(w) v1, v2 = split(v) *Here I also tried defining instead v1, v2 = TestFunctions(W).*
F = fn(u1, u2, u1_, u2_; v1) G = fn(u1, u2, u1_, u2_; v2)
u1, u2 = w.split() *OR does this need to be after the variational problem is solved?* *I tried both with the same outcome.*
solve(F == 0, w)
u1_.assign(u1) u2_.assign(u2).
I see. It turns out support for this option is currently unimplemented in the expression assembler (used for assignment here). However, it should be possible, because the functionspaces all match. The code change to allow this was quite small, so I did so. It is currently waiting on code review but should hopefully be in firedrake master soon: you can see the changes here https://github.com/firedrakeproject/firedrake/pull/400.
This change is now in master. So if you update your firedrake install (you may also need to update FIAT and FFC, but possibly not), rebuild (with make), your problem should go away. Cheers, Lawrence
Dear all, I am trying to solve a simple problem (linear water wave equations), where I have the Laplace equation in a square domain with Neumann boundary conditions on the three sides and on the top boundary two equations are satisfied. I have the following code: -------------------------------------- V = FunctionSpace(mesh,"CG",1) eta0 = Function(V).interpolate(Expression("cos(2*pi*x[0])")) phi0 = Function(V) eta1 = Function(V) phi1 = Function(V) eta = TrialFunction(V) phi = TrialFunction(V) v = TestFunction(V) aeta = v*eta*ds(4) Leta = v*eta0*ds(4) + dt*inner(grad(v),grad(phi0))*dx eta_problem = LinearVariationalProblem(aeta,Leta,eta1) eta_solver = LinearVariationalSolver(eta_problem) aphi = v*phi*ds(4) Lphi = (v*phi0 - g*dt*v*eta1)*ds(4) phi_problem = LinearVariationalProblem(aphi,Lphi,phi1) phi_solver = LinearVariationalSolver(phi_problem) -------------------------------------- The error I get tells me that Object is in wrong state, and Matrix is missing diagonal entry 39. I thought this had to do with the problem being singular, so I tried to build the nullspace but I don't know how to define the VectorSpaceBasis. Any help would be appreciated. Thank you very much. Regards, Anna.
participants (3)
- 
                
                Anna Kalogirou
- 
                
                David Ham
- 
                
                Lawrence Mitchell