Oh, that's much cleaner. Thanks for that, Dan. Ray
On Tue, Mar 19, 2013 at 4:31 PM, Daniel Wheeler <[email protected]>wrote: > I think Raymond pretty much covered all the bases. The way I would write > this is using > > time = Variable(0.) > > eqn = someTerms + mesh.x * mesh.y * t > > for step in range steps: > > eqn.solve(...) > > t.setValue(t.value + dt) > > The key here (due to FiPy pathologies) is to realize that mesh.x and > mesh.y are CellVariables, while using the alternative "x, y = > mesh.cellCenters" syntax does not result in CellVariables, but only numpy > arrays and hence can't be used in the source term unless these are > explicitly cast to a CellVariable. This is because the source term must be > either an object of no length or a CellVariable. Since a "Variable" of no > length multiplied by a CellVarialbe results in a new CellVarialbe "mesh.x * > mesh.y * t" can be used as the souce term function and will know when t > changes. Note that the time "t" has to be explicitly updated in the loop. > > Hope the above helps. > > On Tue, Mar 19, 2013 at 1:26 PM, Raymond Smith <[email protected]> wrote: > >> Hi Serbulent, >> >> I was curious about the same thing, so I gave it a shot. I'm not sure if >> what I've done is a good way to do things, but I think I managed to get a >> source term that's a function of x, y. I modified your script in a number >> of ways, and wrote it so that myFunc takes positions as arguments: >> >> 1) dx should be a float (dx = 1., not dx =1) >> 2) As far as I know, it's better to use fipy's numerix package than numpy. >> 3) I think for a source term that's dependent on position, you can use a >> CellVariable. So I declared a CellVariable, which I then modify values of >> at each time step. >> 4) Rather than loop through x and y and then trying to find the indexes >> that correspond to the a value close to that, you can just loop through all >> the indexes of the grid points in the problem. You can get the X and Y >> arrays which are indexed by this total number of points from >> mesh.CellCenters, then loop through all your points (nx*ny in the >> rectangular 2D case). >> 5) For your time dependence, when you're calling myFunc, you need to have >> calculated what the current time is before you call it (t = >> step*timeStepDuration) >> 6) I made an arbitrary function of x, y, t for myFunc. The way I cast it, >> it takes _values_ of position and time as arguments. The way you wrote it, >> x and y need to be indexes of your "tmp" array. >> >> File at http://pastebin.com/sZLHBTRV >> >> Cheers, >> Ray >> >> >> On Tue, Mar 19, 2013 at 9:43 AM, Serbulent UNSAL <[email protected]>wrote: >> >>> Hi, >>> >>> First thanks to FiPy community for such a practical tool. I'm a newbie >>> in FiPy and try to solve a problem based on source term. >>> >>> My equation is a 2D diffusion equation which has a source term as a >>> function depends on x,y cordinates and time t >>> >>> \frac{ \partial c( \vec{x},t)}{\partial t} = >>> D_{c}\bigtriangledown ^{2} c( \vec{x},t)} - f_{c}( \vec{x},t) >>> >>> I am googleing about 3 days found some clues [1] but they could'nt >>> solve my problem. My code is working with a constant source term but I >>> still couldn't find how can I represent it as a function depends on >>> x,y and t. >>> >>> I'm trying to get my source term values from a mock up matrix for sake >>> of simplicity. I'll be appriciate for any ideas/solutions. My code can >>> be seen at http://pastie.org/6605575 >>> >>> Thanks, >>> >>> Serbulent >>> >>> >>> [1] >>> >>> http://bb10.com/python-fipy/2012-12/msg00016.html >>> http://osdir.com/ml/python.fipy/2007-10/msg00009.html >>> http://bb10.com/python-fipy/2011-05/msg00030.html >>> _______________________________________________ >>> fipy mailing list >>> [email protected] >>> http://www.ctcms.nist.gov/fipy >>> [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] >>> >> >> >> _______________________________________________ >> fipy mailing list >> [email protected] >> http://www.ctcms.nist.gov/fipy >> [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] >> >> > > > -- > Daniel Wheeler > > _______________________________________________ > fipy mailing list > [email protected] > http://www.ctcms.nist.gov/fipy > [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] > >
_______________________________________________ fipy mailing list [email protected] http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
