1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
#############################################################
## ##
## Copyright (c) 2003-2011 by The University of Queensland ##
## Earth Systems Science Computational Centre (ESSCC) ##
## http://www.uq.edu.au/esscc ##
## ##
## Primary Business: Brisbane, Queensland, Australia ##
## Licensed under the Open Software License version 3.0 ##
## http://www.opensource.org/licenses/osl-3.0.php ##
## ##
#############################################################
"""
Defines classes, instances of which, can be used to generate
spherical grains packed with randomly sized circular particles.
"""
from esys.lsm import Logging
from esys.lsm.util import *
from esys.lsm.geometry.GeometryPy import *
def getLogger():
return Logging.getLogger("esys.lsm.geometry")
class ScaledMinMaxGrainGen(RndGrainGen):
"""
Grain generator which can be used in conjunction with
the L{GougeConfigPrms} and L{GrainRandomBoxPacker} classes.
Generates grains which consist of a particles packed into
a circle/sphere. The minimum and maximum particle radii
are scaled with respect to grain size.
@see: getGrain
"""
def __init__(
self,
minGRadius,
maxGRadius,
do2d=False,
radiusScale=(0.1, 0.4),
maxInsertFails=5000
):
"""
Initialise the generator.
@type minGRadius: float
@param minGRadius: minimum grain radius
@type maxGRadius: float
@param maxGRadius: maximum grain radius
@type do2d: bool
@param do2d: If True, grain particles all occur
on the M{z=0} plane (ie particles packed into
a circle).
@type radiusScale: tuple of two floats
@param radiusScale: Randomly generated spherical
particles will have radii which will lie in the range
C{(radiusScale[0]*minGRadius,radiusScale[1]*maxGRadius)}.
"""
self.do2d = do2d
self.maxInsertFails = maxInsertFails
self.minPRadiusScale = radiusScale[0]
self.maxPRadiusScale = radiusScale[1]
minPRadius = self.minPRadiusScale*minGRadius
maxPRadius = self.maxPRadiusScale*maxGRadius
RndGrainGen.__init__(
self,
minGRadius,
maxGRadius,
minPRadius,
maxPRadius
)
def getGrain(self, p):
"""
Uses L{RandomSpherePacker} to create a grain consisting
of randomly sized particles packed into a sphere with
centre C{p.getPosn()} and radius C{p.getRadius()}. The
random particle radii will lie in the range
C{(self.minPRadiusScale*p.getRadius(),self.maxPRadiusScale*p.getRadius())}
@type p: L{SimpleSphere}
@param p: C{p.getPosn()} and C{p.getRadius()} determine
the size and position of the returned grain.
@rtype: L{Grain}
@return: A I{spherical} grain of randomly sized particles.
"""
minRadius=p.getRadius()*self.minPRadiusScale
packer = \
RandomSpherePacker(
minRadius=minRadius,
maxRadius=p.getRadius()*self.maxPRadiusScale,
cubicPackRadius=p.getRadius()*self.maxPRadiusScale,
maxInsertFails=self.maxInsertFails,
bSphere=BoundingSphere(p.getPosn(), p.getRadius()),
do2d=self.do2d,
tolerance = 0.1*minRadius
)
packer.generate()
g = Grain()
for p in packer.getParticleIterator():
g.createParticle(p)
getLogger().info(
"Created grain of " + str(g.getNumParticles()) + " particles"
)
return g
class ScaledMaxGrainGen(RndGrainGen):
"""
Grain generator which can be used in conjunction with
the L{GougeConfigPrms} and L{GrainRandomBoxPacker} classes.
Generates grains which consist of a particles packed into
a circle/sphere. The maximum particle radius
is scaled with respect to grain size, the minimum
particle radius is independent of grain size.
@see: getGrain
"""
def __init__(
self,
minGRadius,
maxGRadius,
do2d=False,
minPRadius=None,
radiusScale=0.1,
maxInsertFails=5000
):
"""
Initialise the generator.
@type minGRadius: float
@param minGRadius: minimum grain radius
@type maxGRadius: float
@param maxGRadius: maximum grain radius
@type do2d: bool
@param do2d: If True, grain particles all occur
on the M{z=0} plane (ie particles packed into
a circle).
@type minPRadius: float
@param minPRadius: The minimum radius of randomly
generated particles.
@type radiusScale: float
@param radiusScale: Randomly generated spherical
particles will have radii which will lie in the range
C{(minPRadius,radiusScale*maxGRadius)}.
"""
if (minPRadius == None):
minPRadius = minGRadius*0.15
self.do2d = do2d
self.maxInsertFails = maxInsertFails
self.minPRadius = minPRadius
self.maxPRadiusScale = radiusScale
maxPRadius = self.maxPRadiusScale*maxGRadius
RndGrainGen.__init__(
self,
minGRadius,
maxGRadius,
minPRadius,
maxPRadius
)
def getGrain(self, p):
"""
Uses L{RandomSpherePacker} to create a grain consisting
of randomly sized particles packed into a sphere with
centre C{p.getPosn()} and radius C{p.getRadius()}. The
random particle radii will lie in the range
C{(self.minPRadius,self.maxPRadiusScale*p.getRadius())}
@type p: L{SimpleSphere}
@param p: C{p.getPosn()} and C{p.getRadius()} determine
the size and position of the returned grain.
@rtype: L{Grain}
@return: A I{spherical} grain of randomly sized particles.
"""
minRadius = self.minPRadius
maxRadius = p.getRadius()*self.maxPRadiusScale
packer = \
RandomSpherePacker(
minRadius=minRadius,
maxRadius=maxRadius,
cubicPackRadius=maxRadius,
maxInsertFails=self.maxInsertFails,
bSphere=BoundingSphere(p.getPosn(), p.getRadius()),
do2d=self.do2d,
tolerance = 0.1*minRadius
)
packer.generate()
g = Grain()
for p in packer.getParticleIterator():
g.createParticle(p)
getLogger().info(
"Created grain of " + str(g.getNumParticles()) + " particles"
)
return g
class AbsGrainGen(RndGrainGen):
"""
Grain generator which can be used in conjunction with
the L{GougeConfigPrms} and L{GrainRandomBoxPacker} classes.
Generates grains which consist of a particles packed into
a circle/sphere. Spherical particle radii are generated
independent of grain size.
@see: getGrain
"""
def __init__(
self,
minGRadius,
maxGRadius,
do2d=False,
minPRadius=None,
maxPRadius=None,
maxInsertFails=5000
):
"""
Initialise the generator.
@type minGRadius: float
@param minGRadius: minimum grain radius
@type maxGRadius: float
@param maxGRadius: maximum grain radius
@type do2d: bool
@param do2d: If True, grain particles all occur
on the M{z=0} plane (ie particles packed into
a circle).
@type minPRadius: float
@param minPRadius: The minimum radius of randomly
generated particles.
@type maxPRadius: float
@param maxPRadius: The maximum radius of randomly
generated particles.
"""
if (maxPRadius == None):
maxPRadius = maxGRadius*0.4
if (minPRadius == None):
minPRadius = maxPRadius*0.15
self.do2d = do2d
self.maxInsertFails = maxInsertFails
self.minPRadius = minPRadius
self.maxPRadius = maxPRadius
RndGrainGen.__init__(
self,
minGRadius,
maxGRadius,
minPRadius,
maxPRadius
)
def getGrain(self, p):
"""
Uses L{RandomSpherePacker} to create a grain consisting
of randomly sized particles packed into a sphere with
centre C{p.getPosn()} and radius C{p.getRadius()}. The
random particle radii will lie in the range
C{(self.minPRadius,self.maxPRadius)}
@type p: L{SimpleSphere}
@param p: C{p.getPosn()} and C{p.getRadius()} determine
the size and position of the returned grain.
@rtype: L{Grain}
@return: A I{spherical} grain of randomly sized particles.
"""
minRadius = self.minPRadius
maxRadius = self.maxPRadius
packer = \
RandomSpherePacker(
minRadius=minRadius,
maxRadius=maxRadius,
cubicPackRadius=maxRadius,
maxInsertFails=self.maxInsertFails,
bSphere=BoundingSphere(p.getPosn(), p.getRadius()),
do2d=self.do2d,
tolerance = 0.1*minRadius
)
packer.generate()
g = Grain()
for p in packer.getParticleIterator():
g.createParticle(p)
getLogger().info(
"Created grain of " + str(g.getNumParticles()) + " particles"
)
return g
|