| 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 gengeo import Vector3, Line2D, BoxWithLines2D, MNTable2D, InsertGenerator2D |
| 14 |
|
| 15 |
#An example python script to generate a 2D bonded rectangle of particles |
| 16 |
|
| 17 |
# Define region extremities: |
| 18 |
minPoint = Vector3(0.0,0.0,0.0) |
| 19 |
maxPoint = Vector3(10.0,10.0,0.0) |
| 20 |
|
| 21 |
# Define the volume to be filled with spheres: |
| 22 |
box = BoxWithLines2D ( |
| 23 |
minPoint = minPoint, |
| 24 |
maxPoint = maxPoint |
| 25 |
) |
| 26 |
|
| 27 |
# Define the geometrical constraints for packing |
| 28 |
top_line = Line2D ( |
| 29 |
startPoint = Vector3(10.0,0.0,0.0), |
| 30 |
endPoint = minPoint |
| 31 |
) |
| 32 |
|
| 33 |
bottom_line = Line2D ( |
| 34 |
startPoint = maxPoint, |
| 35 |
endPoint = Vector3(0.0,10.0,0.0) |
| 36 |
) |
| 37 |
|
| 38 |
left_line = Line2D ( |
| 39 |
startPoint = Vector3(10.0,0.0,0.0), |
| 40 |
endPoint = maxPoint |
| 41 |
) |
| 42 |
|
| 43 |
right_line = Line2D ( |
| 44 |
startPoint = minPoint, |
| 45 |
endPoint = Vector3(0.0,10.0,0.0) |
| 46 |
) |
| 47 |
|
| 48 |
|
| 49 |
box.addLine(top_line) |
| 50 |
box.addLine(bottom_line) |
| 51 |
box.addLine(left_line) |
| 52 |
box.addLine(right_line) |
| 53 |
|
| 54 |
# Create a multi-group neighbour table to contain the particles: |
| 55 |
mntable = MNTable2D ( |
| 56 |
minPoint = minPoint, # specific regional extremities |
| 57 |
maxPoint = maxPoint, |
| 58 |
gridSize = 2.5 # neighbour search algorithm grid size |
| 59 |
) |
| 60 |
|
| 61 |
# Fill the volume with particles: |
| 62 |
packer = InsertGenerator2D ( |
| 63 |
minRadius = 0.1, # minimum radius of spheres to insert |
| 64 |
maxRadius = 0.4, # maximum radius of spheres to insert |
| 65 |
insertFails = 5000, # maximum number of insertion failures |
| 66 |
maxIterations = 1000, # max. iterations for Newton-Raphson solver |
| 67 |
tolerance = 1.0e-5 # max. allowable overlap of spheres |
| 68 |
) |
| 69 |
|
| 70 |
packer.generatePacking( volume = box, ntable = mntable, tag = 0) |
| 71 |
|
| 72 |
# create bonds between neighbouring particles: |
| 73 |
mntable.generateBonds( |
| 74 |
tolerance = 1.0e-5, # max. gap between "touching" particles |
| 75 |
bondID = 0 # bond ID of created bonds |
| 76 |
) |
| 77 |
|
| 78 |
# write the geometry to a file in raw format |
| 79 |
mntable.write( |
| 80 |
fileName = "temp/geo_example1.txt", |
| 81 |
outputStyle = 0 |
| 82 |
) |
| 83 |
|
| 84 |
# write the geometry to an ESyS-Particle geometry file |
| 85 |
mntable.write( |
| 86 |
fileName = "temp/geo_example1.geo", |
| 87 |
outputStyle = 1 |
| 88 |
) |
| 89 |
|
| 90 |
# write the geometry as a VTK file |
| 91 |
mntable.write( |
| 92 |
fileName = "temp/geo_example1.vtu", |
| 93 |
outputStyle = 2 |
| 94 |
) |