3MAH / microgen

Microstructure generation
https://3mah.github.io
GNU General Public License v3.0
65 stars 8 forks source link

Incorrect behaviour for rasterEllipsoid example #26

Closed kmarchais closed 6 months ago

kmarchais commented 9 months ago

Describe the bug, what's wrong, and what you expected.

The example examples/3Doperations/rasterEllipsoid doesn't have the same behaviour as it used to be. It appears that some parts are missing as shown on the screenshot. The bug also appears in the equivalent example of examples/jupyter_notebooks

Steps to reproduce the bug.

import cadquery as cq
import pyvista as pv

from microgen import Ellipsoid, Phase, Rve, mesh, rasterPhase

rve = Rve(dim_x=1, dim_y=1, dim_z=1)

elem = Ellipsoid(a_x=0.15, a_y=0.31, a_z=0.4)
elli = elem.generate()

raster = rasterPhase(phase=Phase(shape=elli), rve=rve, grid=[5, 5, 5])

compound = cq.Compound.makeCompound(
    [solid for phase in raster for solid in phase.solids]
)
cq.exporters.export(compound, "compound.step")

mesh(
    mesh_file="compound.step",
    listPhases=raster,
    size=0.03,
    order=1,
    output_file="rasterEllipsoid.vtk",
)
pv.read("rasterEllipsoid.vtk").plot()

System Information

--------------------------------------------------------------------------------
  Date: Thu Nov 23 17:26:21 2023 Romance Standard Time

                OS : Windows
            CPU(s) : 32
           Machine : AMD64
      Architecture : 64bit
               RAM : 63.7 GiB
       Environment : Python

  Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:29:11) [MSC
  v.1935 64 bit (AMD64)]

           pyvista : 0.42.3
               vtk : 9.3.0
             numpy : 1.26.2
            scooby : 0.9.2
              gmsh : 4.11.1
          cadquery : 2.3.1
        matplotlib : 3.8.2
        pytest-cov : 4.1.0
            meshio : 5.3.4
--------------------------------------------------------------------------------

Screenshots

image

kmarchais commented 9 months ago

Some attempt to try to debug this:

# To run in jupyterlab in a jupyter notebook to be able to quickly visualize the geometry
from microgen import *
from jupyter_cadquery import show, set_defaults, open_viewer
cv = open_viewer("Box", cad_width=640, height=480)
set_defaults(reset_camera=True, show_parent=False, axes=True, axes0=True)

ellipsoid = Ellipsoid(a_x=0.3, a_y=0.3, a_z=0.4)
shape = ellipsoid.generate()

wk_plane = cq.Workplane().add(shape)

grid = [5, 4, 4]

for x in np.linspace(-0.5, 0.5, num=grid[0]):
    plane = cq.Face.makePlane(basePnt=(x, 0, 0), dir=(1, 0, 0))
    wk_plane = wk_plane.split(plane)

for y in np.linspace(-0.5, 0.5, num=grid[1]):
    plane = cq.Face.makePlane(basePnt=(0, y, 0), dir=(0, 1, 0))
    wk_plane = wk_plane.split(plane)

for z in np.linspace(-0.5, 0.5, num=grid[2]):
    plane = cq.Face.makePlane(basePnt=(0, 0, z), dir=(0, 0, 1))
    wk_plane = wk_plane.split(plane)

show(wk_plane)
# show(cq.Compound.makeCompound(wk_plane.val().Solids()))
image image