# Exporting a packing geometry made in yade in a stl format

Hello,

I would like to export a packing geometry of spheres created in yade to a .stl format in order to open it

and read it in a second stage with comsol.

How can I do that ??

Thanks,

Vincent

## Question information

- Language:
- English Edit question

- Status:
- Solved

- For:
- Yade Edit question

- Assignee:
- No assignee Edit question

- Solved by:
- Jan Stránský

- Solved:
- 2020-02-21

- Last query:
- 2020-02-21

- Last reply:
- 2020-02-17

Jan Stránský (honzik) said : | #1 |

Hello,

If it is possible (I don't know comsol), use the spherical data (center + radius).

STL [1] is a file format for triangulated surfaces. So if you need to use STL:

- triangulate the spherical packing

- save triangles in a .stl file [1]

cheers

Jan

Rioual (francois-rioual-v) said : | #2 |

Hello Jan,

Thanks for your reply but:

- How do you triangulate the spherical packing ??

- "save triangles": do you mean i have to build by hands

the stl file as explained in wikipedia i.e. save as a "built up"

text file ???

Best wishes,

V.

Robert Caulk (rcaulk) said : | #3 |

gmsh is one option [1]

Jan Stránský (honzik) said : | #4 |

> - How do you triangulate the spherical packing ??

depending on the meaning of a question:

1) triangulate it such that it suits your needs in comsol

2)

def triangulateOneS

...

return triangles

triangles = [triangulateOne

triangulateOneS

> - "save triangles": do you mean i have to build by hands the stl file as explained in wikipedia i.e. save as a "built up" text file ???

yes. There might be some python stl library for easier processing

Before continuing:

- why do you want to use comsol (what is the background)? is there an alternative, like Paraview?

- is there another file format / method you can use more naturally (than triangulating spheres)? Like [1]?

cheers

Jan

https:/

Rioual (francois-rioual-v) said : | #5 |

Dear Jan,

- My problem is related to the problem of evaporation dynamics in a porous material made with Yade so Comsol is indeed relevant.

- Maybe i will have to find another way to treat the problem from the coordinates and radii of the spheres calculated in Yade if making a stl file is too tough....

Thank you for your input,

V.

Jan Stránský (honzik) said : | #6 |

well, it is not tough (MWE below, probably could be simplified by a meshing/

I just found it unnecessary without enough information

cheers

Jan

###

import stl # pip install stl

class Triangle:

def __init_

self.points = [Vector3(p) for p in (p1,p2,p3)]

def scale(self,factor):

self.points = [p*factor for p in self.points]

return self

def shift(self,v):

self.points = [p+v for p in self.points]

return self

def refine(self): # split 1 triangle into 4

p1,p2,p3 = self.points

p4 = (.5*(p1+

p5 = (.5*(p2+

p6 = (.5*(p3+

return [

]

def toStlFacet(self):

minieigen2stl = lambda v: stl.Vector3d(

p1,p2,p3 = self.points

normal = (p2-p1)

normal = minieigen2stl(

vertices = [minieigen2stl(p) for p in self.points]

return stl.Facet(

def triangulateUnit

xm,xp = [(v,0,0) for v in (-1,+1)]

ym,yp = [(0,v,0) for v in (-1,+1)]

zm,zp = [(0,0,v) for v in (-1,+1)]

return [

Triangle(

Triangle(

Triangle(

Triangle(

Triangle(

Triangle(

Triangle(

Triangle(

]

def triangulateOneS

ret = triangulateUnit

#

for ismooth in range(smooth):

ret2 = []

for t in ret:

ret = ret2

#

c = sph.state.pos

r = sph.shape.radius

for t in ret:

t.

#

return ret

def triangulateSphe

ret = []

for b in O.bodies:

if not isinstance(

ret.

return ret

def spheres2stl(

triangles = triangulateSphe

triangles = [t.toStlFacet() for t in triangles]

solid = stl.Solid()

solid.facets = triangles

with open(fName,"w") as f:

solid.

O.bodies.append((

sphere(

sphere(

sphere(

))

spheres2stl(

spheres2stl(

###

Rioual (francois-rioual-v) said : | #7 |

Thanks Jan Stránský, that solved my question.