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. 

Build the mesh, the cellVariable and give it the values x,y (here cellCenters):

>>> m=Grid2D(nx=4,ny=4)
>>> v=CellVariable(mesh=m,rank=1)
>>> v[0]=m.x
>>> v[1]=m.y

Interpolate the faceValues (I expected in this case, these should be 
faceCenters, clearly theres a difference):

>>> vfv=v.faceValue
>>> vfv[0].value
array([ 0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,
        3.5,  0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,  3.5,  0.5,  1. ,
        2. ,  3. ,  3.5,  0.5,  1. ,  2. ,  3. ,  3.5,  0.5,  1. ,  2. ,
        3. ,  3.5,  0.5,  1. ,  2. ,  3. ,  3.5])
>>> m.faceCenters[0].value
array([ 0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,
        3.5,  0.5,  1.5,  2.5,  3.5,  0.5,  1.5,  2.5,  3.5,  0. ,  1. ,
        2. ,  3. ,  4. ,  0. ,  1. ,  2. ,  3. ,  4. ,  0. ,  1. ,  2. ,
        3. ,  4. ,  0. ,  1. ,  2. ,  3. ,  4. ])
>>> vfv[0].value-m.faceCenters[0].value
array([ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
        0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0.5,  0. ,
        0. ,  0. , -0.5,  0.5,  0. ,  0. ,  0. , -0.5,  0.5,  0. ,  0. ,
        0. , -0.5,  0.5,  0. ,  0. ,  0. , -0.5])

When I compute the divergence from “interpolated” face values versus the 
faceCenters I am getting the following:

>>> vfv.divergence.value
array([ 1. ,  1.5,  1.5,  1. ,  1.5,  2. ,  2. ,  1.5,  1.5,  2. ,  2. ,
        1.5,  1. ,  1.5,  1.5,  1. ])
>>> m.faceCenters.divergence.value
array([ 2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,
        2.,  2.,  2.])

The interpolated face values are not giving what I would expect for the 
divergence. This worries me for when I go to compute more complicated 
quantities. Any pointers are much appreciated. As always I look forward to 
hearing more. 

Best, 
Kyle

_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to