# [Gmsh] Enquiry: making a stl file

Christophe Geuzaine cgeuzaine at uliege.be
Sun Feb 23 20:51:32 CET 2020

```
> On 17 Feb 2020, at 16:06, Rioual Francois <francois.rioual at inrae.fr> wrote:
>
> Good afternoon,
>
> May I write to you concerning my problem:
>  I made a packing a spherical beads (representing a porous material) with a discrete element software (yade).
> So I can have all the coordinates of the centres and radii of the spherical beads.
> I want to save the geometry of this porous medium into a .stl file for further processing (in comsol).
> In order to do that, I was advised to use gmsh; can you explain me how I can proceed ??
>

Here's a simple example to create a cube from which you remove randomly positioned spheres in Gmsh:

DefineConstant[
rmin = {0.02, Name "Min radius"}
rmax = {0.1, Name "Max radius"}
n = {50, Name "Number of spheres"}
];
For i In {1:n}
r = rmin + Rand(rmax - rmin);
x = -0.5 + Rand(1);
y = -0.5 + Rand(1);
z = -0.5 + Rand(1);
Sphere(i) = {x, y, z, r};
EndFor
Block(n + 1) = {-0.5, -0.5, -0.5, 1, 1, 1};
BooleanDifference{ Volume{n+1}; Delete; }{ Volume{1:n}; Delete; }
Mesh.CharacteristicLengthFromCurvature = 1;

You can mesh this in 2D (and save as STL) but you can directly generate a 3D mesh as well directly in Gmsh.

Christophe

>
> Best wishes
>
> Vincent
>
>
> *****************************************************************
> <ZcoSignatureImage_francois 2_image001.png>
> Chargé de Recherches CR1
> Unité FRISE- Génie des procédés frigorifiques pour la sécurité alimentaire et l’environnement
> 1 rue Pierre- Gilles de Gennes  - CS10030
> 92761 Antony Cedex
> Courriel: francois.rioual at inrae.fr
> Tél. : +33 (0)1 40 96 61 21 (poste : 81 90 15)
>  *******************************************************************
>
>
>
>
>
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

—
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine

```