Re: [firedrake] close to fixing my nonlinear QG solver
Pull requests always welcome ;) On Thu, 30 Mar 2017 at 13:24 Francis Poulin <fpoulin@uwaterloo.ca> wrote:
I am sorry that I didn't follow the emails more closely last week. I could have saved myself, and everyone, some time for debugging.
When trying things out I did try help(split), thinking maybe that was the problem. What I found is copied below. It is, let's say, terse.
I agree with Colin, if someone could insert something on the docs spelling out the difference that could be very helpful for other people who might very well come across the same issue.
Cheers, Francis
P.S. I will go back and reread old emails to understand why this is the correct syntax.
Help on function split in module ufl.split_functions:
split(v) UFL operator: If v is a Coefficient or Argument in a mixed space, returns a tuple with the function components corresponding to the subelements.
------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo
email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 <(519)%20888-4567>
------------------------------ *From:* firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Colin Cotter [colin.cotter@imperial.ac.uk] *Sent:* Thursday, March 30, 2017 7:59 AM *To:* firedrake
*Subject:* Re: [firedrake] close to fixing my nonlinear QG solver It's a classic gotcha. We are kind of stuck with it due to wanting to stay close to the Fenics interface, but maybe we should have a specific bit in the docs about it [or a more highlighted one, if it already exists].
all the best --cjc
On 30 March 2017 at 12:57, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Houston, we have convergence!
Thank you for the help Lawrence.
I did see there were emails about the split passed around last week, which I clearly should have read more closely.
Now that I have convergence on a course grid I will test a finder grid and let you know how robust this is.
Cheers, Francis
------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo
email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637
________________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk] Sent: Thursday, March 30, 2017 7:14 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] close to fixing my nonlinear QG solver
Hi Francis,
sorry, I now saw your problem.
You do:
soln1.assign(soln0)
psi1, u1, q1 = soln1.split()
Gnon = F(psi1, u1, q1)
You've been bitten by the "wrong split" bug!! ARGH.
Only use function.split() for output. If you're going to use the split values in a form, you need to use "split(function)"
If you replace your lines:
psi1, u1, q1 = soln1.split() Gnon = ...
with:
psi1, u1, q1 = split(soln1) Gnon = ... psi1, u1, q1 = soln1.split()
Everything works.
Lawrence
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- http://www.imperial.ac.uk/people/colin.cotter
www.cambridge.org/9781107663916
-- Dr David Ham Department of Mathematics Imperial College London
Okay, I will try and put together something helpful in the next day or two and run it by you all. Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of David Ham [David.Ham@imperial.ac.uk] Sent: Thursday, March 30, 2017 8:32 AM To: firedrake Subject: Re: [firedrake] close to fixing my nonlinear QG solver Pull requests always welcome ;) On Thu, 30 Mar 2017 at 13:24 Francis Poulin <fpoulin@uwaterloo.ca<mailto:fpoulin@uwaterloo.ca>> wrote: I am sorry that I didn't follow the emails more closely last week. I could have saved myself, and everyone, some time for debugging. When trying things out I did try help(split), thinking maybe that was the problem. What I found is copied below. It is, let's say, terse. I agree with Colin, if someone could insert something on the docs spelling out the difference that could be very helpful for other people who might very well come across the same issue. Cheers, Francis P.S. I will go back and reread old emails to understand why this is the correct syntax. Help on function split in module ufl.split_functions: split(v) UFL operator: If v is a Coefficient or Argument in a mixed space, returns a tuple with the function components corresponding to the subelements. ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca<mailto:fpoulin@uwaterloo.ca> Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637<tel:(519)%20888-4567> ________________________________ From: firedrake-bounces@imperial.ac.uk<mailto:firedrake-bounces@imperial.ac.uk> [firedrake-bounces@imperial.ac.uk<mailto:firedrake-bounces@imperial.ac.uk>] on behalf of Colin Cotter [colin.cotter@imperial.ac.uk<mailto:colin.cotter@imperial.ac.uk>] Sent: Thursday, March 30, 2017 7:59 AM To: firedrake Subject: Re: [firedrake] close to fixing my nonlinear QG solver It's a classic gotcha. We are kind of stuck with it due to wanting to stay close to the Fenics interface, but maybe we should have a specific bit in the docs about it [or a more highlighted one, if it already exists]. all the best --cjc On 30 March 2017 at 12:57, Francis Poulin <fpoulin@uwaterloo.ca<mailto:fpoulin@uwaterloo.ca>> wrote: Houston, we have convergence! Thank you for the help Lawrence. I did see there were emails about the split passed around last week, which I clearly should have read more closely. Now that I have convergence on a course grid I will test a finder grid and let you know how robust this is. Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca<mailto:fpoulin@uwaterloo.ca> Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637<tel:%2B1%20519%20888%204567%20x32637> ________________________________________ From: firedrake-bounces@imperial.ac.uk<mailto:firedrake-bounces@imperial.ac.uk> [firedrake-bounces@imperial.ac.uk<mailto:firedrake-bounces@imperial.ac.uk>] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk<mailto:lawrence.mitchell@imperial.ac.uk>] Sent: Thursday, March 30, 2017 7:14 AM To: firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> Subject: Re: [firedrake] close to fixing my nonlinear QG solver Hi Francis, sorry, I now saw your problem. You do: soln1.assign(soln0) psi1, u1, q1 = soln1.split() Gnon = F(psi1, u1, q1) You've been bitten by the "wrong split" bug!! ARGH. Only use function.split() for output. If you're going to use the split values in a form, you need to use "split(function)" If you replace your lines: psi1, u1, q1 = soln1.split() Gnon = ... with: psi1, u1, q1 = split(soln1) Gnon = ... psi1, u1, q1 = soln1.split() Everything works. Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk<mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake -- http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916<http://www.cambridge.org/9781107663916> [http://assets.cambridge.org/97811076/63916/cover/9781107663916.jpg] -- Dr David Ham Department of Mathematics Imperial College London
On 30 Mar 2017, at 14:41, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Okay, I will try and put together something helpful in the next day or two and run it by you all.
FWIW, we have now added error checking for this common case, so if you now attempt to take a derivative wrt u and your form contains something from u.split(), then you'll get a (hopefully informative) error message. Let us know if this does the job. Lawrence
Thanks Lawrence. That sounds very helpful. I update my firedrake and will give it a try. I thought I understand the difference but I am a bit confused. Suppose that Z = V1*V2*V3 If I define a trial or test function in Z, say and want to split it, I would have thought i used split(FunctionOnZ). But that does not go over well. What worked in the end is (a,b,c) = FunctionOnZ Is this a third way of splitting a function? Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk] Sent: Friday, March 31, 2017 10:12 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] close to fixing my nonlinear QG solver
On 30 Mar 2017, at 14:41, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Okay, I will try and put together something helpful in the next day or two and run it by you all.
FWIW, we have now added error checking for this common case, so if you now attempt to take a derivative wrt u and your form contains something from u.split(), then you'll get a (hopefully informative) error message. Let us know if this does the job. Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 31 Mar 2017, at 15:40, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Thanks Lawrence.
That sounds very helpful. I update my firedrake and will give it a try.
I thought I understand the difference but I am a bit confused.
Suppose that Z = V1*V2*V3
If I define a trial or test function in Z, say and want to split it, I would have thought i used split(FunctionOnZ). But that does not go over well. What worked in the end is
(a,b,c) = FunctionOnZ
Is this a third way of splitting a function?
Can you show what you tried to do? The following works for me: mesh = ... V = FunctionSpace(mesh, "DG", 0) Q = FunctionSpace(mesh, "DG", 1) W = V*Q w = TestFunction(W) v, q = split(w) In fact, writing v, q = TestFunctions(W) is just a short hand for: v, q = split(TestFunction(W)) Lawrence
I agree that splitting the function straight away is more efficient and I normally want to do that. But I am defining a function and thought it's easier to pass one field rather than two. What I tried was the following: V1 = FunctionSpace(mesh, "CG", 3) V2 = FunctionSpace(mesh, "BDM", 2) V3 = FunctionSpace(mesh, "DG", 1) Z = V1 * V2 * V3 # TEST/TRIAL FUNCTIONS Ztrial = TrialFunctions(Z) Ztest = TestFunctions(Z) a,b,c = split(Ztest) and I get the error copied below. Sorry if I am missing something obvious but I can say that if I define a,b,c = TestFunction(Z) that does work. Cheers, Francis --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-7-69c5a9f01474> in <module>() ----> 1 a,b,c = split(Ztest) /home/fpoulin/software/firedrake/src/ufl/ufl/split_functions.pyc in split(v) 64 65 # Special case: simple element, just return function in a tuple ---> 66 element = v.ufl_element() 67 if not isinstance(element, MixedElement): 68 assert end is None AttributeError: 'tuple' object has no attribute 'ufl_element' ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk] Sent: Friday, March 31, 2017 10:46 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] close to fixing my nonlinear QG solver
On 31 Mar 2017, at 15:40, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Thanks Lawrence.
That sounds very helpful. I update my firedrake and will give it a try.
I thought I understand the difference but I am a bit confused.
Suppose that Z = V1*V2*V3
If I define a trial or test function in Z, say and want to split it, I would have thought i used split(FunctionOnZ). But that does not go over well. What worked in the end is
(a,b,c) = FunctionOnZ
Is this a third way of splitting a function?
Can you show what you tried to do? The following works for me: mesh = ... V = FunctionSpace(mesh, "DG", 0) Q = FunctionSpace(mesh, "DG", 1) W = V*Q w = TestFunction(W) v, q = split(w) In fact, writing v, q = TestFunctions(W) is just a short hand for: v, q = split(TestFunction(W)) Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 31 Mar 2017, at 16:12, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
...
# TEST/TRIAL FUNCTIONS Ztrial = TrialFunctions(Z) Ztest = TestFunctions(Z) ^ a,b,c = split(Ztest)
and I get the error copied below.
Sorry if I am missing something obvious but I can say that if I define
a,b,c = TestFunction(Z)
^ In the first instance, you wrote TestFunctions and TrialFunctions (note the trailing s), whereas in the working code you wrote TestFunction. The former returns a tuple of indexed objects, whereas the latter returns a single TestFunction. Lawrence
Argh! Thank for catching my inability to spell properly (and debug effectively). Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk] Sent: Friday, March 31, 2017 11:33 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] close to fixing my nonlinear QG solver
On 31 Mar 2017, at 16:12, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
...
# TEST/TRIAL FUNCTIONS Ztrial = TrialFunctions(Z) Ztest = TestFunctions(Z) ^ a,b,c = split(Ztest)
and I get the error copied below.
Sorry if I am missing something obvious but I can say that if I define
a,b,c = TestFunction(Z)
^ In the first instance, you wrote TestFunctions and TrialFunctions (note the trailing s), whereas in the working code you wrote TestFunction. The former returns a tuple of indexed objects, whereas the latter returns a single TestFunction. Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (3)
- 
                
                David Ham
- 
                
                Francis Poulin
- 
                
                Lawrence Mitchell