On Jan 18, 2008, at 3:47 PM, Rashmi Ranjan Mohanty wrote:
I am trying to calculate the volume/area fraction of second phase
particles in a matrix across the length of the system.
The system is in 2D and the particles are distributed in random.
Particles and the matrix phases are distinguished by the
composition variable. More precisely, I want the distribution of
area fraction of particles across the system (area fractions
calculated on sections of the system along x-axis), not the total
area fraction of the system. This needs to be calculated in each
time iteration step. I was trying to do it with the "histogram" but
could not figure it out. Is their any way to do this? Any
suggestion will be appreciated.
This is how I would approach it (assuming FiPy 1.2):
from fipy import *
# make a mesh
mesh = Grid2D(nx=100, ny=100, dx=0.1, dy=0.1)
x = mesh.getCellCenters()[...,0]
y = mesh.getCellCenters()[...,1]
L = 100 * 0.1
# make a bunch of circular seeds
phi = CellVariable(mesh=mesh)
for cx, cy, r in numerix.random.random((20,3)):
phi.setValue(1, where=(x - cx*L)**2 + (y - cy*L)**2 < (r *
L / 30)**2)
viewer = viewers.make(vars=phi, limits={'datamin':0, 'datamax': 1})
# get the area fraction by masking out everything we don't care
about
# and comparing the total area of the masked data with the total
area of the mask
sliceThickness = L / 10.
mask = CellVariable(mesh=mesh)
for slice in range(0, L, sliceThickness):
mask.setValue(((slice <= x) & (x < slice + L/10.)))
print "%g <= x < %g:" % (slice, slice + L/10.), (phi *
mask).getCellVolumeAverage() / mask.getCellVolumeAverage()
Since you say you're using the composition variable to identify the
phases, you'll want to substitute something like ((composition >
Cthreshold) * mask).getCellVolumeAverage()
It seems like HistogramVariable should be adaptable to this, but I
haven't used it in a long time and would need to think about it for
awhile.