The expression I wrote before:

  kp['NO3'] = (k['R2'] * k_O2_NO3/(k_O2_NO3 + O2.var)) * (Qcc != 0)

is a lazily evaluated binop that will be set to zero whenever Qcc == 0, but is 
the desired expression otherwise.


As to your code, it's too complicated for me to analyze in detail. I *strongly* 
recommend you work out the structure of your code with two or, at most, three 
reactions.

I can say, thought, that none of the coefficients you are setting between 
307-373 have any bearing on your solution because m.eqI has already been 
defined in terms of the initial values of those coefficients. Writing 

  kp['FeS'] = k['R13'] * O2.var 

(or whatever), simply creates a new thing and puts it in the dictionary kp with 
key 'FeS'. It discards the reference to whatever was in that dict slot before. 
m.eqI doesn't see that, though; it's still defined in terms of references to 
what was originally in the dict.

P.S. Please keep these questions on the list. We don't have the resources to 
provide private help.

On Feb 15, 2014, at 4:14 PM, yuan wang <[email protected]> wrote:

> Dear Jon and Daniel,
> 
> Sorry I didn't make myself clear about the objective. What I want to do is to 
> update the nonlinear source term for each sweep. I would like to use the lazy 
> evaluation, but the problem is that the nonlinear coefficient is dependent on 
> another cellvariable (Qcc). (If Qcc is zero, the reaction stops.) So, I feel 
> I have to put that within the sweeping loop to update it, because it is 
> within the loop that I could get a real time Qcc evaluation. 
> 
> Please find my code attached. Line 307-373 are updating the coefficients for 
> implicit source term and explicit source term. It is running and converges 
> after 18 sweeps. I think there should be a way to improve the efficiency, but 
> as a beginner I'm not sure how to do that. Would you please advise me how it 
> could be improved? 
> 
> Thanks for your support!
> 
> Best regards,
> Rose
> 
> 
> 
> On Tue, Feb 11, 2014 at 2:21 PM, Guyer, Jonathan E. Dr. 
> <[email protected]> wrote:
> 
> On Feb 11, 2014, at 11:39 AM, Daniel Wheeler <[email protected]> 
> wrote:
> 
> > On Mon, Feb 10, 2014 at 9:02 PM, yuan wang <[email protected]> wrote:
> > My guess is that "copy()" just returns a plain old CellVariable
> > without its dependencies. Basically, the "copy()" is not exactly the
> > same object as the original.
> >
> > Unfortunately, I'm not sure what you are trying to do above, I think
> > I'd need to see the full traceback to debug it. My hunch is that you
> > should be doing either
> >
> >    kp['NO3'][:] = numerix.array((k['R2'] * k_O2_NO3/(k_O2_NO3 + O2.var)))
> >
> > to cast the RHS to be an array rather than a variable, if you want to
> > not have kp['NO3'] updated via lazy evaluation.
> 
> Likewise, I don't understand what the actual objective is, here.
> 
> I suspect you *do* want lazy evaluation and that what should be written is 
> something like
> 
>   kp['NO3'] = (k['R2'] * k_O2_NO3/(k_O2_NO3 + O2.var)) * (Qcc != 0)
> 
> and then *never re-write kp['NO3'] again*!!! If you are using FiPy properly, 
> there should never be a "when it hits to the next time" because you only 
> write expressions like this once and you let lazy evaluation take care of 
> updating the values.
> 
> .copy() is a red herring. It apparently does produce a CellVariable, but I 
> don't think it should.
> 
> Please work through some of FiPy's examples that involve non-linear 
> coefficients. These would be some good ones to start with:
> 
> http://www.ctcms.nist.gov/fipy/examples/diffusion/generated/examples.diffusion.mesh1D.html
> http://www.ctcms.nist.gov/fipy/examples/phase/generated/examples.phase.simple.html
> http://www.ctcms.nist.gov/fipy/examples/phase/generated/examples.phase.quaternary.html
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> 
> 
> 
> -- 
> Yuan (Rose) Wang
> PhD Candidate, Tufts University
> Cellphone: 617-699-8006
> <Sed2K_15_Feb_Monod.py>


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to