| 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 * |
| 14 |
#An example python script to generate a union/intersection of two volumes |
| 15 |
|
| 16 |
# Define region extremities: |
| 17 |
maxRadius = 1.0 |
| 18 |
size = 20.0 |
| 19 |
minPoint = Vector3(0.0,0.0,0.0) |
| 20 |
maxPoint = Vector3(size,size,size) |
| 21 |
|
| 22 |
minPt = Vector3(0,0,0) |
| 23 |
maxPt = Vector3(size,0.5*size,size) |
| 24 |
# Define the first volume to be filled with spheres: |
| 25 |
box = BoxWithPlanes3D ( |
| 26 |
minPoint = minPt, |
| 27 |
maxPoint = maxPt |
| 28 |
) |
| 29 |
|
| 30 |
box.addPlane( |
| 31 |
Plane( |
| 32 |
origin = minPt, |
| 33 |
normal = Vector3(1.0,0.0,0.0) |
| 34 |
) |
| 35 |
) |
| 36 |
#or the compact form: |
| 37 |
box.addPlane(Plane(minPt, Vector3(0.0,1.0,0.0))) |
| 38 |
box.addPlane(Plane(minPt, Vector3(0.0,0.0,1.0))) |
| 39 |
box.addPlane(Plane(maxPt, Vector3(-1.0,0.0,0.0))) |
| 40 |
box.addPlane(Plane(maxPt, Vector3(0.0,-1.0,0.0))) |
| 41 |
box.addPlane(Plane(maxPt, Vector3(0.0,0.0,-1.0))) |
| 42 |
|
| 43 |
sphere = SphereVol ( |
| 44 |
centre = Vector3(0.5*size,0.5*size,0.5*size), |
| 45 |
radius = 0.5*size |
| 46 |
) |
| 47 |
|
| 48 |
sphere1 = SphereVol ( |
| 49 |
centre = Vector3(0.5*size,0.75*size,0.5*size), |
| 50 |
radius = 0.5*size |
| 51 |
) |
| 52 |
|
| 53 |
sphere2 = SphereVol ( |
| 54 |
centre = Vector3(0.5*size,0.25*size,0.5*size), |
| 55 |
radius = 0.5*size |
| 56 |
) |
| 57 |
|
| 58 |
cylinder = CylinderVol ( |
| 59 |
origin = Vector3 (0.5*size,0,0.5*size), |
| 60 |
axis = Vector3 (0,1,0), |
| 61 |
length = 0.5*size, |
| 62 |
radius = 0.5*size |
| 63 |
) |
| 64 |
|
| 65 |
cylinder2 = CylinderVol ( |
| 66 |
origin = Vector3 (0.5*size,0,0.5*size), |
| 67 |
axis = Vector3 (0,1,0), |
| 68 |
length = 0.5*size, |
| 69 |
radius = 0.4*size |
| 70 |
) |
| 71 |
|
| 72 |
cylinder3 = CylinderVol ( |
| 73 |
origin = Vector3 (0.5*size,0.25*size,0.5*size), |
| 74 |
axis = Vector3 (0,1,0), |
| 75 |
length = 0.5*size, |
| 76 |
radius = 0.3*size |
| 77 |
) |
| 78 |
|
| 79 |
unionVol = UnionVol ( |
| 80 |
volume1 = sphere, |
| 81 |
volume2 = cylinder |
| 82 |
) |
| 83 |
|
| 84 |
intersectionVol = IntersectionVol ( |
| 85 |
volume1 = sphere1, |
| 86 |
volume2 = sphere2 |
| 87 |
) |
| 88 |
|
| 89 |
differenceVol = DifferenceVol ( |
| 90 |
volume1 = cylinder, |
| 91 |
volume2 = cylinder2 |
| 92 |
) |
| 93 |
|
| 94 |
differenceVol2 = DifferenceVol ( |
| 95 |
volume1 = cylinder, |
| 96 |
volume2 = sphere1 |
| 97 |
) |
| 98 |
|
| 99 |
differenceVol3 = DifferenceVol ( |
| 100 |
volume1 = cylinder, |
| 101 |
volume2 = cylinder3 |
| 102 |
) |
| 103 |
|
| 104 |
# Create a multi-group neighbour table to contain the particles: |
| 105 |
mntable = MNTable3D ( |
| 106 |
minPoint = minPoint, |
| 107 |
maxPoint = maxPoint, |
| 108 |
gridSize = 2.5*maxRadius |
| 109 |
) |
| 110 |
|
| 111 |
# Fill the volume with particles: |
| 112 |
packer = InsertGenerator3D ( |
| 113 |
minRadius = 0.2, |
| 114 |
maxRadius = maxRadius, |
| 115 |
insertFails = 1000, |
| 116 |
maxIterations = 1000, |
| 117 |
tolerance = 1.0e-6 |
| 118 |
) |
| 119 |
|
| 120 |
packer.generatePacking( |
| 121 |
# volume = unionVol, |
| 122 |
# volume = intersectionVol, |
| 123 |
# volume = differenceVol, |
| 124 |
volume = differenceVol2, |
| 125 |
# volume = differenceVol3, |
| 126 |
# volume = cylinder, |
| 127 |
ntable = mntable |
| 128 |
) |
| 129 |
|
| 130 |
# create bonds between neighbouring particles: |
| 131 |
mntable.generateBonds( |
| 132 |
tolerance = 1.0e-5, |
| 133 |
bondID = 0 |
| 134 |
) |
| 135 |
|
| 136 |
mntable.tagParticlesInVolume ( |
| 137 |
volume = differenceVol, |
| 138 |
tag = 12345 |
| 139 |
) |
| 140 |
|
| 141 |
# write a geometry file |
| 142 |
mntable.write( |
| 143 |
fileName = "temp/geo_example10.vtu", |
| 144 |
outputStyle = 2 |
| 145 |
) |
| 146 |
|
| 147 |
mntable.write( |
| 148 |
fileName = "temp/geo_example10.raw", |
| 149 |
outputStyle = 0 |
| 150 |
) |
| 151 |
|
| 152 |
mntable.write( |
| 153 |
fileName = "temp/geo_example10.geo", |
| 154 |
outputStyle = 1 |
| 155 |
) |