| 1 |
############################################################# |
| 2 |
## ## |
| 3 |
## Copyright (c) 2007-2017 by The University of Queensland ## |
| 4 |
## Centre for Geoscience Computing ## |
| 5 |
## http://earth.uq.edu.au/centre-geoscience-computing ## |
| 6 |
## ## |
| 7 |
## Primary Business: Brisbane, Queensland, Australia ## |
| 8 |
## Licensed under the Open Software License version 3.0 ## |
| 9 |
## http://www.apache.org/licenses/LICENSE-2.0 ## |
| 10 |
## ## |
| 11 |
############################################################# |
| 12 |
|
| 13 |
#from __future__ import print_function |
| 14 |
from __future__ import division |
| 15 |
from gengeo import Sphere, Vector3, Line2D, BoxWithLines2D, MNTable2D, InsertGenerator2D |
| 16 |
from random import random |
| 17 |
|
| 18 |
# An example python script to generate a bonded rectangle of particles |
| 19 |
# and cluster the particles inside the rectangle |
| 20 |
|
| 21 |
# Define region extremities: |
| 22 |
xsize=20.0 |
| 23 |
ysize=20.0 |
| 24 |
minPoint = Vector3(0.0,0.0,0.0) |
| 25 |
maxPoint = Vector3(xsize,ysize,0.0) |
| 26 |
|
| 27 |
# Define the geometrical constraints for packing |
| 28 |
# (e.g. lines bordering a rectangular region in 2D) |
| 29 |
top_line = Line2D ( |
| 30 |
startPoint = Vector3(xsize,0.0,0.0), |
| 31 |
endPoint = minPoint |
| 32 |
) |
| 33 |
|
| 34 |
bottom_line = Line2D ( |
| 35 |
startPoint = maxPoint, |
| 36 |
endPoint = Vector3(0.0,ysize,0.0) |
| 37 |
) |
| 38 |
|
| 39 |
left_line = Line2D ( |
| 40 |
startPoint = Vector3(xsize,0.0,0.0), |
| 41 |
endPoint = maxPoint |
| 42 |
) |
| 43 |
|
| 44 |
right_line = Line2D ( |
| 45 |
startPoint = minPoint, |
| 46 |
endPoint = Vector3(0.0,ysize,0.0) |
| 47 |
) |
| 48 |
|
| 49 |
# Define the Volume to be filled with spheres: |
| 50 |
box = BoxWithLines2D ( |
| 51 |
minPoint = minPoint, |
| 52 |
maxPoint = maxPoint |
| 53 |
) |
| 54 |
|
| 55 |
box.addLine(top_line) |
| 56 |
box.addLine(bottom_line) |
| 57 |
box.addLine(left_line) |
| 58 |
box.addLine(right_line) |
| 59 |
|
| 60 |
# Create a multi-group neighbour table to contain the particles: |
| 61 |
mntable = MNTable2D ( |
| 62 |
minPoint = minPoint, |
| 63 |
maxPoint = maxPoint, |
| 64 |
gridSize = 2.5, |
| 65 |
numGroups = 2 |
| 66 |
) |
| 67 |
|
| 68 |
# Fill the volume with particles: |
| 69 |
packer = InsertGenerator2D ( |
| 70 |
minRadius = 0.1, |
| 71 |
maxRadius = 1.0, |
| 72 |
insertFails = 1000, |
| 73 |
maxIterations = 1000, |
| 74 |
tolerance = 1.0e-6, |
| 75 |
seed=0 |
| 76 |
) |
| 77 |
|
| 78 |
packer.generatePacking( volume = box, ntable = mntable, groupID = 0, tag = 0) |
| 79 |
|
| 80 |
# insert zero-radius particles in group 2 as a cluster seeds |
| 81 |
# use randomly disturbed square grid |
| 82 |
nx=5 |
| 83 |
ny=5 |
| 84 |
for i in range(nx): |
| 85 |
for j in range(ny): |
| 86 |
xpos=(float(i)+random())*xsize/float(nx) |
| 87 |
ypos=(float(j)+random())*ysize/float(ny) |
| 88 |
cseed=Sphere(Vector3(xpos,ypos,0.0),0.0) |
| 89 |
# cseed.setTag(i*ny+j) |
| 90 |
cseed.setTag(int(random()*nx*ny)) |
| 91 |
mntable.insert( |
| 92 |
sphere=cseed, |
| 93 |
groupID=1 |
| 94 |
) |
| 95 |
#print("xpos: ",xpos) |
| 96 |
|
| 97 |
mntable.tagParticlesToClosest( |
| 98 |
groupID1=0, |
| 99 |
groupID2=1 |
| 100 |
) |
| 101 |
|
| 102 |
# create cluster bonds between neighbouring particles |
| 103 |
# bonds between particles with the same tag will have bondTag1 |
| 104 |
# bonds between particles with different tags will have bondTag2 |
| 105 |
mntable.generateClusterBonds( |
| 106 |
groupID = 0, |
| 107 |
tolerance = 1.0e-5, |
| 108 |
bondTag1 = 0, |
| 109 |
bondTag2 = 1, |
| 110 |
) |
| 111 |
|
| 112 |
|
| 113 |
# write a geometry file |
| 114 |
mntable.write( |
| 115 |
fileName = "temp/cluster.geo", |
| 116 |
outputStyle = 1 |
| 117 |
) |
| 118 |
|
| 119 |
# write a vtk file |
| 120 |
mntable.write( |
| 121 |
fileName = "temp/cluster.vtu", |
| 122 |
outputStyle = 2 |
| 123 |
) |