On Tue, Dec 4, 2012 at 9:24 AM, Lafras Uys <[email protected]> wrote:

> Dear List,
>
> I have a FiPy model of the following form:
>
> from fipy import Grid1D, CellVariable
> from fipy import TransientTerm, DiffusionTerm
> from fipy.tools.numerix import linspace, zeros
>
> cs = ('a','b',)
>
> class Toy:
>
>     def __init__(self):
>
>         self.L = 1.0
>         self.nx = 10
>         self.dx = self.L/self.nx
>
>         self.m = Grid1D(dx=self.dx,nx=self.nx)
>
>         for v in cs:
>             c = CellVariable(self.m, name=v, hasOld=1)
>             setattr(self,v,c)
>
>     def setInitial(self):
>
>         self.a.setValue(linspace(1,7,self.nx))
>         self.b.setValue(1)
>
>
>     def evaluate(self,o):
>
>         self.setInitial()
>
>         a = self.a
>         b = self.b
>
>         D = -0.00004 * b
>
>         v = o[0] * a/(1+a)
>         w = o[1] * b/(1+b)
>
>         e = TransientTerm() + DiffusionTerm(D) == v - w
>
>         zs = 10
>         du = 0.1
>
>         err = 10**-6
>         res = zeros((zs,self.nx))
>
>         for z in range(zs):
>             r = 10**3
>             res[z] = b.getValue()
>             while r > err:
>                 r = min(r, e.sweep(b,dt=du))
>             b.updateOld()
>
>         return res
>
> if __name__ == "__main__":
>
>     t = Toy()
>     o = [1.,1.]
>     print t.evaluate(o)
>
> This is a stripped down version of the problem I'm solving. In reality
> I have twelve PDEs and some hairy non-linear source terms. I've had
> problems when I converted my "script" version, i.e. not classes of my
> own, to a version where my problem is neatly packaged into a class and
> all instances of CellVariables etc. are local to some method. My
> question is: will this confuse FiPy or not?
>

Not sure.


> What I mean is: will all
> variables be updated as they should be after each iteration of sweep &
> updateOld?
>

All "var.updateOld()" does is update the var's old value. Each CellVariable
(if "var.hasOld = True") has an "old" attribute, which is itself a
CellVariable. If the CellVariable has ("hasOld = False") then "var.old =
var". Now, the TransientTerm simply uses "(var - var.old) / dt". If there
are no sweeps then an old value is not required as "var" is implicit.
However, if your problem does have sweeps then you require an old value
otherwise "var.old" will be the value from the previous sweep rather than
the previous time step. Thus, if you use sweeps, you need to call
updateOld() on all your CellVariable's between each time step.

Hope that helps.

Cheers

-- 
Daniel Wheeler
_______________________________________________
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