Re: error in gradient even with orthogonal grid

2016-08-02 Thread James Pringle
Thank you -- since my problem solves for a stream function, this was a very
helpful tip, and has made my solutions appear much better.

Jamie

On Mon, Aug 1, 2016 at 4:49 PM, Daniel Wheeler 
wrote:

> Hi Jamie,
>
> Sorry for the delayed reply.
>
> On Thu, Jul 21, 2016 at 11:31 AM, James Pringle  wrote:
> >
> > However, I am still getting large errors in estimates of the gradient
> even
> > when the mesh is nearly perfectly orthogonal. These errors DO NOT become
> > smaller as resolution is increased. I have two question:
> >
> > Are these errors to be expected in unstructured meshes?
>
> Cell centered FV has two issues with unstructured meshes. You know
> about the orthogonality issue, but there is a second issue. The
> docstring from the following code might help explain,
>
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_usnistgov_fipy_blob_develop_fipy_variables_cellVariable.py-23L257&d=DQICAg&c=c6MrceVCY5m5A_KAUkrdoA&r=7HJI3EH6RqKWf16fbYIYKw&m=F8ThJ6NxKtDlYIWkDUqGq2ql_J0shUHQMI1lQCB1Wvo&s=RM15FSI_eegFR5VfTb9il1PZ2B1_yaQ6eKmZHq-8Hx0&e=
>
> See, `\frac{1}{V_P} \sum_f \vec{n} \phi_f A_f`. This is the
> discretized gradient calculation. In this formulation using the
> triangular mesh, the calculated \phi_f is not the correct average for
> the face as the line between the cell centers doesn't cross the face
> in the middle of the face. I think this is called non-conjunctionality
> in finite volume speak. See equation 9.8 in the following link for
> further explanation (we should probably implement this approach).
>
>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__bit.ly_2aqRiHt&d=DQICAg&c=c6MrceVCY5m5A_KAUkrdoA&r=7HJI3EH6RqKWf16fbYIYKw&m=F8ThJ6NxKtDlYIWkDUqGq2ql_J0shUHQMI1lQCB1Wvo&s=EJ34X0r43RF50EgJ2p_clCS-H5yY8nSTitKGqtbINts&e=
>
> I believe that this is the source of the error in the gradient
> calculation. It's a consistent error independent of the mesh
> refinement I think (or maybe first order). An alternative gradient
> calculation is the least squares gradient, see
>
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_usnistgov_fipy_blob_develop_fipy_variables_cellVariable.py-23L270&d=DQICAg&c=c6MrceVCY5m5A_KAUkrdoA&r=7HJI3EH6RqKWf16fbYIYKw&m=F8ThJ6NxKtDlYIWkDUqGq2ql_J0shUHQMI1lQCB1Wvo&s=l6F4maMJnB3bfM6--FXXLzrUKyaH1i7KHuo1atLYJqM&e=
>
> Using that
>
> 
> import fipy as fp
> nx = 25
> dx = 1. / nx
> mesh = fp.Tri2D(nx=nx, ny=nx, dx=dx, dy=dx)
> psi = fp.CellVariable(mesh=mesh)
> psi.constrain(1.0, where=mesh.facesLeft)
> psi.faceGrad.constrain(1.0, where=mesh.facesRight)
> eq = fp.DiffusionTerm().solve(psi)
> print psi.leastSquaresGrad[:, :100]
> 
>
> seems to give lots of 1s and 0s which seems correct. The cells next to
> the boundary are not correct as they aren't using the boundary
> conditions in the calculation. I'm not sure about the order of
> accuracy of the least squares or why it happens to work for this mesh.
>
> > Is it acceptable to average the gradient over space to reduce the error?
>
> I don't think so unless it can be shown to improve the accuracy with
> analysis.
>
> --
> Daniel Wheeler
> ___
> fipy mailing list
> fipy@nist.gov
>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.ctcms.nist.gov_fipy&d=DQICAg&c=c6MrceVCY5m5A_KAUkrdoA&r=7HJI3EH6RqKWf16fbYIYKw&m=F8ThJ6NxKtDlYIWkDUqGq2ql_J0shUHQMI1lQCB1Wvo&s=A7D0acjE011uAk-Vl-5OhrTNVdH9kgmq0rshSN6tbsg&e=
>   [ NIST internal ONLY:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__email.nist.gov_mailman_listinfo_fipy&d=DQICAg&c=c6MrceVCY5m5A_KAUkrdoA&r=7HJI3EH6RqKWf16fbYIYKw&m=F8ThJ6NxKtDlYIWkDUqGq2ql_J0shUHQMI1lQCB1Wvo&s=V8y_Fr-VcNq0fTtFnfiyabj8MXL8mmGa5LFCMv0Sx_Q&e=
> ]
>
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: error in gradient even with orthogonal grid

2016-08-01 Thread Daniel Wheeler
Hi Jamie,

Sorry for the delayed reply.

On Thu, Jul 21, 2016 at 11:31 AM, James Pringle  wrote:
>
> However, I am still getting large errors in estimates of the gradient even
> when the mesh is nearly perfectly orthogonal. These errors DO NOT become
> smaller as resolution is increased. I have two question:
>
> Are these errors to be expected in unstructured meshes?

Cell centered FV has two issues with unstructured meshes. You know
about the orthogonality issue, but there is a second issue. The
docstring from the following code might help explain,


https://github.com/usnistgov/fipy/blob/develop/fipy/variables/cellVariable.py#L257

See, `\frac{1}{V_P} \sum_f \vec{n} \phi_f A_f`. This is the
discretized gradient calculation. In this formulation using the
triangular mesh, the calculated \phi_f is not the correct average for
the face as the line between the cell centers doesn't cross the face
in the middle of the face. I think this is called non-conjunctionality
in finite volume speak. See equation 9.8 in the following link for
further explanation (we should probably implement this approach).

   http://bit.ly/2aqRiHt

I believe that this is the source of the error in the gradient
calculation. It's a consistent error independent of the mesh
refinement I think (or maybe first order). An alternative gradient
calculation is the least squares gradient, see

   
https://github.com/usnistgov/fipy/blob/develop/fipy/variables/cellVariable.py#L270

Using that


import fipy as fp
nx = 25
dx = 1. / nx
mesh = fp.Tri2D(nx=nx, ny=nx, dx=dx, dy=dx)
psi = fp.CellVariable(mesh=mesh)
psi.constrain(1.0, where=mesh.facesLeft)
psi.faceGrad.constrain(1.0, where=mesh.facesRight)
eq = fp.DiffusionTerm().solve(psi)
print psi.leastSquaresGrad[:, :100]


seems to give lots of 1s and 0s which seems correct. The cells next to
the boundary are not correct as they aren't using the boundary
conditions in the calculation. I'm not sure about the order of
accuracy of the least squares or why it happens to work for this mesh.

> Is it acceptable to average the gradient over space to reduce the error?

I don't think so unless it can be shown to improve the accuracy with analysis.

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