Good Afternoon (Morning) to all,

I have an equation of type

*eq = TransientTerm() == DiffusionTerm(coeff=D) + sourceGrid - sinkGrid*

Where sourceGrid and sinkGrid are derived from values in a 3D grid.

Is there any downside to declaring the grids as

*sourceGrid = CellVariable(name="source", mesh=Grid3D(dx=1, dy=1, dz=1,
nx=20, ny=20, nz=20))*
*        sinkGrid = CellVariable(name="sink", mesh=Grid3D(dx=1, dy=1, dz=1,
nx=20, ny=20, nz=20))*

And populating them as:

 *i = np.ravel_multi_index([coordinate[0], coordinate[1], coordinate[2]],
(20, 20, 20))*

*            sourceGrid._array[i] = sourceRate*
*            sinkGrid._array[i] = sinkRate*

The original procedure I was using (given below) where I called .setValue
on each coordinate is extremely time-consuming. Results seem to align, but
of course this doesn't mean it's right... Or if it's wrong, any specific
advice on how to achieve this?

Thanks,
Dario

Original approach (and there is an equivalent function for setupSinkGrid):
*def setupSourceGrid_(self, sourceCoords, mesh):*
*        sourceGrid = CellVariable(name="source", mesh=mesh, value=0)*
*        sourceGrid.setValue(0.)*
*        for pos, v in sourceCoords.iteritems():*
*            tmpGrid = [False for _ in range(8000)]*
*            i = np.ravel_multi_index([pos[0], pos[1], pos[2]], (20, 20,
20))*
*            tmpGrid[i] = True*
*            sourceGrid.setValue(v, where=tmpGrid)*
_______________________________________________
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