On May 23, 2012, at 10:45 PM, I wrote:
> For small values of N\phi and Ny, I think the following would do the trick.
> For larger numbers of variables and equations, I have some ideas, but would
> need to experiment a little.
OK, it looks like you can use memory and store values a bit more efficiently by
taking advantage of NumPy "views":
----
phi = [CellVariable(mesh=mesh, name=r"$\phi_%d$" % i, hasOld=True) for i in
range(Nphi)]
y = [CellVariable(mesh=mesh, name=r"$y_%d$" % i, hasOld=True) for i in
range(Ny)]
ystore = numerix.empty((Ny * Nx,))
for var, arr in zip(y, numerix.split(ystore, Ny)):
var.value = arr
----
and then in your solve loop, do:
----
ystore[:] = scipy.optimize.fsolve(func=F,
x0=ystore,
args=(phi,))
----
This is for FiPy 2.1. If you are using trunk, then switch to "var._value = arr".
You can use views again in your F function like this:
----
def F(x, *args):
y = numerix.split(x, Ny)
...
----
There are probably ways to vectorize the result of your F function using arrays
of parameters, as well, but I leave that as an exercise for the reader.
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]