On Wed, Jun 15, 2011 at 11:50 AM, Igor <gozdawa.a...@googlemail.com> wrote:
>
> Hello all,
>
> does anybody have an idea how to perform integration of fipy
> CellVariables over one of the "variables" representing cell centers of
> 2D mesh?
>
> For example:
>
> dx=0.1
> dy=0.2
> nx=10
> ny=10
> mesh_xy=Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
> xc,yc=mesh_xy.getCellCenters()
>
> def F(x,y):
>     return x+y
>
> N=CellVariable(mesh=mesh_xy, value=F(xc,yc))

A low order approximation is simply

   (N * mesh.getCellVolumes()).sum()

when N is defined to be point locations.

> F(x,y) is for illustrative purposes only. In general N will be a
> solution of conv-diff. problem at given time.

In that case (N * mesh.getCellVolumes()).sum() is no longer an
approximation since N is defined as the cell average in the FVM (not
the value of N at a given location). Obviously, the derivation of N
using the numerical approximation will have an associated error, but
the integral is error free.

> I'd like to know int_A^B N*yc*dy, A and B are some limits.

Just need to create a mask defining some region.

  mask = (x > 0.5) & (y > 0.2)
  integral =  (mask * N * mesh.getCellVolumes()).sum()

for example.

> I would
> also like the result be of ndarray type (i.e., representing the
> integrated value at each xc).

Not sure what you are asking. The integral is obviously independent of location.

Hope the above helps.

-- 
Daniel Wheeler


Reply via email to