Debian Codegraph @

examples/gengeo_exampleShapeList.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 = 4.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 # QUESTION: Are there constraints on normals e.g. inward facing?
26 box = BoxWithPlanes3D (
27 minPoint = minPoint,
28 maxPoint = maxPoint
29 )
30
31 box.addPlane(
32 Plane(
33 origin = minPoint,
34 normal = Vector3(1.0,0.0,0.0)
35 )
36 )
37 #or the compact form:
38 box.addPlane(Plane(minPoint, Vector3(0.0,1.0,0.0)))
39 box.addPlane(Plane(minPoint, Vector3(0.0,0.0,1.0)))
40 box.addPlane(Plane(maxPoint, Vector3(-1.0,0.0,0.0)))
41 box.addPlane(Plane(maxPoint, Vector3(0.0,-1.0,0.0)))
42 box.addPlane(Plane(maxPoint, Vector3(0.0,0.0,-1.0)))
43
44 # Create a multi-group neighbour table to contain the particles:
45 mntable = MNTable3D (
46 minPoint = minPoint,
47 maxPoint = maxPoint,
48 gridSize = 2.5*maxRadius
49 )
50
51
52 sList = ShapeList()
53
54 sList.addGenericShape(
55 db = "shapeDatabase.db",
56 name = "sphere",
57 bias = 1,
58 random = 1,
59 particleTag = 1,
60 bondTag = 1
61 )
62
63 sList.addGenericShape(
64 db = "shapeDatabase.db",
65 name = "test",
66 bias = 5,
67 random = 1,
68 particleTag = 2,
69 bondTag = 2
70 )
71
72 # Fill the volume with particles:
73 packer = InsertGenerator3D (
74 minRadius = 0.2,
75 maxRadius = maxRadius,
76 insertFails = 1000,
77 maxIterations = 1000,
78 tolerance = 1.0e-6
79 )
80
81 packer.generatePacking(
82 volume = box,
83 ntable = mntable,
84 tag = 0,
85 shapeList = sList
86 )
87
88 # print the porosity:
89 volume = 2.0*size*size*size
90 porosity = (volume - mntable.getSumVolume())/volume
91 print("Porosity: ", porosity)
92
93 # write a geometry file in VTK format
94 mntable.write(
95 fileName = "temp/geo_exampleShapeList.vtu",
96 outputStyle = 2
97 )
98
99 # write a geometry file in raw (debug) format
100 mntable.write(
101 fileName = "temp/geo_exampleShapeList.raw",
102 outputStyle = 0
103 )
104
105 # write a geometry file in gengeo file format
106 mntable.write(
107 fileName = "temp/geo_exampleShapeList.geo",
108 outputStyle = 1
109 )
110