2014-06-20 16:24 GMT+02:00 Daniel Wheeler daniel.wheel...@gmail.com:
On Thu, Jun 19, 2014 at 11:53 AM, Benny Malengier
benny.maleng...@gmail.com wrote:
Hi,
another question. This time on SourceTerm use. I'm checking an article
with
diffusion and reaction. So some species diffuse, others only react
(waiting
for diffused species to start). If there is an example with this
floating on
the internet, do point it my way!
Not that I'm aware of.
You then have a coupled set of equations, of which one of the non
diffusive
species will have equation like
eqn3 = TransientTerm(var=P0) == ImplicitSourceTerm(-k3*M1, var=P0) +
ImplicitSourceTerm(-k5*M2, var=P0)
eqn4 = TransientTerm(var=P1) == ImplicitSourceTerm(k3*P0, var=M1)
M1 will have another equation that has a diffusionterm.
In eqn3 it is normal to use ImplicitSourceTerm as the rhs has -k3 M1 P0.
Yes, but the right splitting for -k3 * M1 * P0 is probably
k3 * M1 * P0 - ImplicitSourceTerm(k3 * M1, var=P0) -
ImplicitSourceTerm(k3 * P0, var=M1)
In eqn4, we could actually write
eqn4 = TransientTerm(var=P1) == k3*P0*M1
or
eqn4 = TransientTerm(var=P1) == ImplicitSourceTerm(k3*M1, var=P0)
In light that all will be coupled in one equation to solve, will this
lead
to different solutions?
It shouldn't assuming that there isn't an instability. Eventually,
they should converge to the same result, but not at the the same rate.
Or will fipy internally all give this the same
matrix formulation?
It certainly won't give the same matrix formulation for different
implicit / explicit choices. User needs to be aware of what's going
on.
Also, in eqn3, the first term in rhs is actually -k3 M1 P0. It seems
nicest
if somehow it is guaranteed that values as in eqn4 for this term would be
used. Will this be the case in this formulation?
Don't understand the question fully. Do you mean that it would be nice
to be using the latest value of M1? This won't happen as M1 is
explicit in Equation 3. Either P0 is explicit or M1 will be
explicit in Equation 3 (or both). There is no way to avoid this.
Perhaps there is a way to do this nicer and introduce a helper variable,
U=M1*P0, so as to have only in eqn3 and eqn4 ImplicitSourceTerm(-k3,
var=U)
and ImplicitSourceTerm(k3, var=U) respectively. If so, how to go about
to do
this. If I do ImplicitSourceTerm(-k3, var=M1*P0) I get immediately the
error
fipy.terms.SolutionVariableNumberError: Different number of solution
variables and equations.
The helper variable won't buy you anything. Use a Taylor expansion to
make the correct explicit / implicit choice
S = Sc + var1 * dS / dvar1 + var2 * dS / dvar2
if S is the source term. The other choice would be to do full Newton
iteration.
So, I would need an equation for U, would that be
eqnhelper = ImplicitSourceTerm(1, var=U) == M1*P0
Or am I making things too complicated now.
This doesn't help since you still have an explicit representation for
M1 and P0 in one of the equations.
Thanks for the pointers, I'll try some things. My FiPy knowledge is slowly
getting back.
My main question seems to have come down on how intelligent the coupling
mechanism in fipy is as opposed to using the old sweep and updating values
when finished. If I understand you correctly, only the var option of
ImplicitSourceTerm comes into play (
http://www.ctcms.nist.gov/fipy/examples/diffusion/generated/examples.diffusion.coupled.html
) so the other var present are explicit, also after coupling. Seems the
logical thing.
So, next question would be, can I use the nicer new notation suitable for
coupling, and nevertheless sweep the coupled equation? But sweep requires a
var option, so that seems not possible on the coupled equation, but perhaps
is still possible on the seperate equations (would be nice if the coupled
equation var could be passed in some way ...). So I could envision, doing
one solve on the coupled equation, then doing sweep equation per equation,
and continuing that till low residuals are obtained.
If no sweeping is used, I would expect it best to take equal parts explicit
and implicit. So not as you say
k3 * M1 * P0 - ImplicitSourceTerm(k3 * M1, var=P0) -
ImplicitSourceTerm(k3 * P0, var=M1)
but
- 1/2 *ImplicitSourceTerm(k3 * M1, var=P0) - 1/2*ImplicitSourceTerm(k3 *
P0, var=M1)
or if a fully explicit term is used, then 1/3 of three terms.
If sweeping of equations written like that is supported, then sweeping this
should go to full implicit.
Anyway, my code is working already, so I can try different formulations out
myself and see how much they result in different solutions.
In case you wonder what I try to reproduce, see figures and equation in
http://rspb.royalsocietypublishing.org/content/271/1548/1565
It's nice that after some hours with fipy you have a fully working script
:-). But then the nagging question of how correct everything is pops up off