Thanks, Daniel. Is the function .getGrad() built to handle irregular meshes as well? I’ll be honest I have no intuition for what is meant by the first index being the “direction” and the second index being the direction for the gradient operator.
I’ve written out the grad of a vector in 2D:
gradient_vector.pdf
Description: Adobe PDF document
What does “direction" mean? Would the gradient direction be the direction of the grad(f_1) and grad(f_2)? Looking forward to hearing more and thanks ahead of time. Kyle On Dec 24, 2014, at 10:18 AM, Daniel Wheeler <[email protected]> wrote: > On Tue, Dec 23, 2014 at 3:50 PM, Kyle Briton Lawlor > <[email protected]> wrote: >> Hi again, Fipy. >> >> Suppose that with a solution variable phi (that is a cellVariable), I >> construct a vector field so that there is a vector associated to each point >> on the cell centers of the mesh, is there a way I could compute the gradient >> of that vector field with FiPy? > > Hi Kyle, > > I think that works, at least this does > > In [1]: import fipy as fp > > In [2]: m = fp.Grid2D(nx=3, ny=3) > > In [4]: v = fp.CellVariable(mesh=m, rank=1) > > In [5]: v.shape > Out[5]: (2, 9) > > In [6]: v[0] = m.x > > In [7]: v[1] = m.x * m.y > > In [10]: print v.getGrad() > [[[ 0.5 1. 0.5 0.5 1. 0.5 0.5 1. 0.5 ] > [ 0.25 0.5 0.25 0.75 1.5 0.75 1.25 2.5 1.25]] > > [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. ] > [ 0.25 0.75 1.25 0.5 1.5 2.5 0.25 0.75 1.25]]] > > In [11]: print v.getGrad().shape > (2, 2, 9) > > The first index is the direction, the second index is the direction > for the gradient operator and the last index is over the cells. > > In [12]: print v.getGrad()[0] > [[ 0.5 1. 0.5 0.5 1. 0.5 0.5 1. 0.5 ] > [ 0.25 0.5 0.25 0.75 1.5 0.75 1.25 2.5 1.25]] > > In [13]: print v.getGrad()[:,0] > [[ 0.5 1. 0.5 0.5 1. 0.5 0.5 1. 0.5] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. ]] > > > -- > 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 ]
