CIC
Name
CIC
Purpose
Interpolate an irregularly sampled field using Cloud in Cell method
Explanation
This function interpolates an irregularly sampled field to a
regular grid using Cloud In Cell (nearest grid point gets
weight 1-dngp, point on other side gets weight dngp, where
dngp is the distance to the nearest grid point in units of the
cell size).
Category
Mathematical functions, Interpolation
Calling Sequence
Result = CIC, VALUE, POSX, NX[, POSY, NY, POSZ, NZ,
AVERAGE = average, WRAPAROUND = wraparound,
ISOLATED = isolated, NO_MESSAGE = no_message]
Inputs
VALUE: Array of sample weights (field values). For e.g. a
temperature field this would be the temperature and the
keyword AVERAGE should be set. For e.g. a density field
this could be either the particle mass (AVERAGE should
not be set) or the density (AVERAGE should be set).
POSX: Array of X coordinates of field samples, unit indices: [0,NX>.
NX: Desired number of grid points in X-direction.
Optional Inputs
POSY: Array of Y coordinates of field samples, unit indices: [0,NY>.
NY: Desired number of grid points in Y-direction.
POSZ: Array of Z coordinates of field samples, unit indices: [0,NZ>.
NZ: Desired number of grid points in Z-direction.
Keyword Parameters
AVERAGE: Set this keyword if the nodes contain field samples
(e.g. a temperature field). The value at each grid
point will then be the weighted average of all the
samples allocated to it. If this keyword is not
set, the value at each grid point will be the
weighted sum of all the nodes allocated to it
(e.g. for a density field from a distribution of
particles). (D=0).
WRAPAROUND: Set this keyword if you want the first grid point
to contain samples of both sides of the volume
(see below).
ISOLATED: Set this keyword if the data is isolated, i.e. not
periodic. In that case total `mass' is not conserved.
This keyword cannot be used in combination with the
keyword WRAPAROUND.
NO_MESSAGE: Suppress informational messages.
Example of default allocation of nearest grid points: n0=4, *=gridpoint.
0 1 2 3 Index of gridpoints
* * * * Grid points
|---|---|---|---| Range allocated to gridpoints ([0.0,1.0> --> 0, etc.)
0 1 2 3 4 posx
Example of ngp allocation for WRAPAROUND: n0=4, *=gridpoint.
0 1 2 3 Index of gridpoints
* * * * Grid points
|---|---|---|---|-- Range allocated to gridpoints ([0.5,1.5> --> 1, etc.)
0 1 2 3 4=0 posx
Outputs
Prints that a CIC interpolation is being performed of x
samples to y grid points, unless NO_MESSAGE is set.
Restrictions
Field data is assumed to be periodic with the sampled volume
the basic cell, unless ISOLATED is set.
All input arrays must have the same dimensions.
Postition coordinates should be in `index units' of the
desired grid: POSX=[0,NX>, etc.
Keywords ISOLATED and WRAPAROUND cannot both be set.
Procedure
Nearest grid point is determined for each sample.
CIC weights are computed for each sample.
Samples are interpolated to the grid.
Grid point values are computed (sum or average of samples).
Notes
Use tsc.pro for a higher-order interpolation scheme, ngp.pro for a lower
order interpolation scheme. A standard reference for these
interpolation methods is: R.W. Hockney and J.W. Eastwood, Computer
Simulations Using Particles (New York: McGraw-Hill, 1981).
Example
nx=20
ny=10
posx=randomu(s,1000)
posy=randomu(s,1000)
value=posx^2+posy^2
field=cic(value,posx*nx,nx,posy*ny,ny,/average)
surface,field,/lego
Modification History
Written by Joop Schaye, Feb 1999.
Avoid integer overflow for large dimensions P.Riley/W.Landsman Dec. 1999