# Triangular Mesh Packing using GenGeo

Asked by Bin Cheng on 2017-09-07

Hi everyone,

I am trying to use GenGeo to generate a triangular mesh packing, but I found that there is not detailed documents or tutorial on the packing with complicated geometries. So, how could I read mesh file and transfer it to GenGeo? Maybe using the class MeshVolume? I am not sure how to use this class through gengeo.TriPatchSet.

Best wishes,

Bin Cheng.

## Question information

Language:
English Edit question
Status:
Solved
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Solved by:
Dion Weatherley
Solved:
2017-09-10
Last query:
2017-09-10
2017-09-09
 Dion Weatherley (d-weatherley) said on 2017-09-09: #1

Hi Bin,

Below is a relatively minimalist example for packing a mesh with particles using gengeo. I hope this helps.

Cheers,

Dion

script for packing a triangular pyramid with particles:
=========================================

from gengeo import *

def pyramidMesh(sideLength=20.):
p0 = Vector3(0.,0.,0.)
p1 = Vector3(20.,0.,0.)
p2 = Vector3(10.,0.,10.)
p3 = Vector3(10.,20.,10.)

pyramidTris = TriPatchSet()

pyramid = MeshVolume(Mesh=pyramidTris)

return pyramid

def mkPacking (mesh=None,Rmin=0.3,Rmax=1.0):
minPoint = Vector3(0.,0.,0.)
maxPoint = Vector3(20.,20.,20.)

mntable = MNTable3D (
minPoint,maxPoint,2.5*Rmax,1
)

packer = InsertGenerator3D (
Rmin,Rmax,10000,1000,1.0e-6,True
)

packer.generatePacking(mesh,mntable,0,1)

mntable.generateBonds(0,1.e-5,1)

mntable.write("pyramid.geo",1)
mntable.write("pyramid.geo.vtu",2)

if __name__=="__main__":
mkPacking(mesh=pyramidMesh())

 Bin Cheng (bincheng) said on 2017-09-10: #3

Thanks Dion. It works.

Here are my code. It reads two files, named "points.txt" and "cells.txt". And it would be easy to change it to read standard ESyS-Particle TriMesh file.

Hope it would help someone.

===================================================
# --- geometry setup script for simple box ---
from gengeo import *
# -- parameters --
# block dimensions
xdim=12000
ydim=12000
zdim=12000
# particle size range
# ---------------------
# corner points
minPoint = Vector3(-xdim,-ydim,-zdim)
maxPoint = Vector3(xdim,ydim,zdim)
# ---------------------
with open('points.txt','r') as f:
points = []
for line in data:
point = line.split()
point = map(float, point)
_point = Vector3(point[0], point[1], point[2])
points.append(_point)
# mesh setting
TriMesh = TriPatchSet()
with open('cells.txt','r') as c:
for line in data:
cell = line.split()
cell = map(int, cell)
p0 = points[cell[0]]
p1 = points[cell[1]]
p2 = points[cell[2]]
TriMeshVolume = MeshVolume(Mesh = TriMesh)
print 'mntable begin'
# neighbour table
# -- setup packer --
# iteration parameters
insertFails = 10000
maxIter = 1000
tol = 1.0e-6
# packer
# pack particles into volume
print 'packing begin'
packer.generatePacking(TriMeshVolume,mntable)
print 'packing end'
# create bonds between neighbouring particles:
#mntable.generateBonds(0,1.0e-5,0)
# write a geometry file