# Meshing cube including inside particles

Hello, I’m trying to make a cube geometry including inside particles.

Here is the code I use so far.

``````"""
The constructive solid geometry (CSG) format allows to define geometric primitives such as
spheres and cylinders and perform to boolean operations on them.
"""
import numpy as np
import time
from netgen.csg import *
from ngsolve.webgui import Draw
import netgen.gui

geo = CSGeometry()

# Make cube
cube = OrthoBrick( Pnt(0,0,0), Pnt(64,64,64) )

# Read Coordinates_XYZ from *.txt file.
# Read AxisLength_abc from *.txt file. This is semi-AxisLength.

# Make Ellipsoids based on given information
t0_start = time.time()
ellips = [0] * len(Coordinates_XYZ[:,0])
for i in range(0, 10):
ellips[i] = Ellipsoid(Pnt(Coordinates_XYZ[i,0],Coordinates_XYZ[i,1],Coordinates_XYZ[i,2]),
Vec(AxisLength_abc[i,0],0,0),
Vec(0,AxisLength_abc[i,1],0),
Vec(0,0,AxisLength_abc[i,2]))
print(i)
t0_end = time.time()
print("Making ellipsoids took --- %s seconds ---" % (t0_end - t0_start))

t1_start = time.time()
ngmesh = geo.GenerateMesh()
t1_end = time.time()
print("GenerateMesh took --- %s seconds ---" % (t1_end - t1_start))

# for visualization we need a NGSolve mesh
from ngsolve import Mesh
# Draw(Mesh(ngmesh)) => We don't need "Draw(somthing)", only Mesh(ngmesh).
# Check the result in NGSolve GUI.
Mesh(ngmesh)
``````

I’d like to do meshing the volume only within the cube.

In other words, if there is some volume(area) of ellipsoid outside the cube, I would not like to include that partial volume. I know there is a boolean, but I don’t know how to utilize this function.

Also, after meshing, it looks like just one whole part. I cannot specify (select) each particle inside the cube. When I import the STL file into COMSOL. I cannot select the particles.

So, what should I do to select the particles even after the meshing?

Are there any ways to do Volumetric mesh? When importing STL file, inside volume looks hollow.