Debian Codegraph @

examples/gengeo_example2.py

raw
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 division, print_function
14 from gengeo import *
15 #An example python script to generate a bonded rectangular prism
16
17 # Define region extremities:
18 maxRadius = 1.0
19 size = 10.0
20 minPoint = Vector3(0.0,0.0,0.0)
21 maxPoint = Vector3(size,2.0*size,size)
22
23 # Define the volume to be filled with spheres:
24 # (e.g. a box bounded by planes)
25 box = BoxWithPlanes3D (
26 minPoint = minPoint,
27 maxPoint = maxPoint
28 )
29
30 box.addPlane(
31 Plane(
32 origin = minPoint,
33 normal = Vector3(1.0,0.0,0.0)
34 )
35 )
36 #or the compact form:
37 box.addPlane(Plane(minPoint, Vector3(0.0,1.0,0.0)))
38 box.addPlane(Plane(minPoint, Vector3(0.0,0.0,1.0)))
39 box.addPlane(Plane(maxPoint, Vector3(-1.0,0.0,0.0)))
40 box.addPlane(Plane(maxPoint, Vector3(0.0,-1.0,0.0)))
41 box.addPlane(Plane(maxPoint, Vector3(0.0,0.0,-1.0)))
42
43 # Create a multi-group neighbour table to contain the particles:
44 mntable = MNTable3D (
45 minPoint = minPoint,
46 maxPoint = maxPoint,
47 gridSize = 2.5*maxRadius
48 )
49
50 # Fill the volume with particles:
51 packer = InsertGenerator3D (
52 minRadius = 0.2,
53 maxRadius = maxRadius,
54 insertFails = 1000,
55 maxIterations = 1000,
56 tolerance = 1.0e-6
57 )
58
59 # Instruct packer to generate the particle packing
60 packer.generatePacking(
61 volume = box,
62 ntable = mntable
63 )
64
65 # create bonds between neighbouring particles:
66 mntable.generateBonds(
67 tolerance = 1.0e-5,
68 bondID = 0
69 )
70
71 # print the porosity:
72 volume = 2.0*size*size*size
73 porosity = (volume - mntable.getSumVolume())/volume
74 print("Porosity: ", porosity)
75
76 # write the geometry to a VTK file
77 mntable.write(
78 fileName = "temp/geo_example2.vtu",
79 outputStyle = 2
80 )
81
82 # write the geometry to an ESyS-Particle geo file
83 mntable.write(
84 fileName = "temp/geo_example2.geo",
85 outputStyle = 1
86 )