On Fri, Jan 2, 2015 at 4:42 PM, Kyle Briton Lawlor <klawlor...@gmail.com> wrote: > Hi FiPy, > > I am toying around with the following problem, suppose there is a vector > field v=(x,y) and I am looking to compute div(v)=2 with FiPy. I know that > the .divergence property is for FaceVariables but suppose we need to build > the vector field from a CellVariable. As far as I know, from the > CellVariable I can get face values with .faceValue. So I looked to test this > sort of procedure with the simple case stated above.
Kyle, Unfortunately, FiPy just assumes the exterior face values are the same as the cell centers unless constrained to be something else. Setting, v[0] = m.x v[1] = m.y only sets the cell center values. A CellVariable knows nothing about the functional form of the object that set its values. The following does work however > import fipy as fp > m = fp.Grid2D(nx=4, ny=4) > v = fp.CellVariable(mesh=m, rank=1) > v[0] = m.x > v[1] = m.y > X, Y = m.faceCenters > v.faceValue.constrain((X, Y), where=m.exteriorFaces) > v.faceValue.divergence [ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.] Unfortunately, this doesn't help very much. There is no way for FiPy to know what the intended face values should be since the only information held by the cell variable is its cell center values (plus any additional constraints). There is know assumption about the exterior face values made in FiPy based on the cell center gradients (since the cell center gradients are calculated from the cell center values). Arguably, setting a faceGrad constraint should influence the extrapolation, but it doesn't currently. Hope this helps. Cheers. -- Daniel Wheeler _______________________________________________ fipy mailing list fipy@nist.gov http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]