On Mon, Jan 7, 2013 at 12:55 PM, Salomon Turgman Cohen <[email protected]>wrote:
> Hey Daniel, > > No problem. That is what I get for emailing late Friday afternoon! I > attach a script that I wrote during the weekend that I thought worked well. > It seems to be a generic way to generate linear interpolation in a > piecewise manner for an arbitrary number of data points. It also uses the > current features of FiPy including the CellVariable.arithmeticFaceValue and > the FaceVariable.setValue commands. Is there anything wrong with this > approach? > This is fine as long as you only do one step or one sweep as you are doing in the attached script. However, if you want D to to be dependent on phi (so that when phi is updated, D is also updated) then you will need the method that I outlined in my first email. An example might help here In [1]: import fipy as fp In [2]: a = fp.Variable(1.) In [4]: b = fp.Variable(2.) In [5]: b Out[5]: Variable(value=array(2.0)) In [6]: c = a * b In [7]: print c 2.0 In [8]: c Out[8]: (Variable(value=array(1.0)) * Variable(value=array(2.0))) "c" knows it depends on "a" and "b". In [9]: a.setValue(2) In [10]: print c 4.0 If "a" changes value then so does "c". In [12]: d = fp.Variable() Make a new variable "d" and make it have the value of "a * b" In [13]: d.setValue(a * b) In [14]: d Out[14]: Variable(value=array(4.0)) "d" doesn't know about "a" or "b". In [16]: print d 4.0 In [17]: a.setValue(4) In [18]: print d 4.0 In [19]: print c 8.0 Hope the above helps sort it our for you. In your case you don't need to explicitly instantiate "D", it can be created via the result of a calculation and then it will have the correct dependencies. Cheers, -- Daniel Wheeler
_______________________________________________ fipy mailing list [email protected] http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
