Skip to content

Refactor/shape#141

Open
chemiskyy wants to merge 5 commits into
mainfrom
refactor/shape
Open

Refactor/shape#141
chemiskyy wants to merge 5 commits into
mainfrom
refactor/shape

Conversation

@chemiskyy
Copy link
Copy Markdown
Member

This pull request introduces several improvements and new features to the microgen package, focusing on enhanced support for implicit shapes, periodic geometry, and improved type safety and API consistency. The most significant changes include the addition of a robust, immutable Rve (Representative Volume Element) class, a new utility for sewing periodic triangle meshes into closed CAD shells, and improved type definitions for implicit shape operations. There are also API cleanups, such as the removal of unused rotation utilities and the addition of new shape types.

New features and enhancements:

  • Introduced a frozen, immutable Rve class in microgen/rve.py, providing a more robust and type-safe container for RVE geometry, periodicity flags, and structured grid generation. This replaces the previous mutable class and adds validation and convenience methods. [1] [2]
  • Added mesh_to_periodic_shell in microgen/shape/periodic_shell.py, a utility that sews periodic triangulated surfaces into closed OCCT shells, supporting periodic TPMS and spinodoid shapes.
  • Added shape_to_cad in microgen/cad.py, a generic bridge for converting implicit Shape instances to CAD BREP using surface meshing, improving support for arbitrary implicit shapes.
  • Added microgen/shape/_types.py with shared type aliases (Field, BoundsType, PeriodType) for implicit shape operations, centralizing definitions and improving type safety across the codebase.

API changes and cleanups:

  • Removed the unused rotate_pv_euler function and its exports from the codebase for clarity and to avoid confusion. [1] [2] [3]
  • Updated Box.generate_surface_mesh to support explicit bounds and resolution parameters, falling back to the base implementation when these are provided for polymorphic compatibility.
  • Added new shapes (GradedInfill, Sweep) to the public API and import lists, making them available for downstream use. [1] [2] [3] [4] F1f9f521L21R21, [5] [6]

Internal improvements:

  • Updated type annotations and imports throughout the codebase to use the new shared type aliases, improving consistency and maintainability. [1] [2]

These changes collectively improve the flexibility, correctness, and maintainability of the microgen package, especially for advanced use cases involving implicit and periodic geometry.

chemiskyy added 5 commits May 21, 2026 18:52
Make Shape.generate_surface_mesh polymorphic for Box, Sphere and Spinodoid by accepting optional bounds/resolution and falling back to the SDF/marching-cubes path when callers request explicit sampling. Add BoundsType imports and update docstrings to explain the behavior. Remove the legacy rotate_pv_euler function and its export from operations/__init__ (cleanup of Euler helper). Tidy Rve by removing unused is_matrix/matrix_number defaults. Expose new TPMS-related classes (GradedInfill, Sweep) in shape exports and update __all__ accordingly. Add a lint test (tests/test_no_top_level_ocp_imports.py) to prevent top-level OCP imports outside the CAD boundary.
Make Rve a frozen dataclass with validated inputs and explicit pbc flags. Introduce helper validators, cached min_point/max_point and a cached box property (lazy CAD box creation). Add Rve.grid(...) to produce a pyvista.StructuredGrid with flexible resolution handling. Improve __repr__ and update from_min_max to accept pbc. Expand tests to cover pbc behavior, immutability, min/max consistency, grid generation, invalid inputs, and repr content.
Introduce shared shape type aliases and an intrinsic period attribute, and add a generic CAD bridge and periodic-shell sewing.

- Add microgen/shape/_types.py with Field, BoundsType and PeriodType aliases to centralize type defs.
- Add microgen/shape/periodic_shell.py: mesh_to_periodic_shell builds sewn OCCT shells with planar cap faces for periodic meshes.
- Add shape_to_cad in microgen/cad.py: generic fallback to build a tessellated CadShape from an implicit Shape.
- Update microgen/shape/shape.py: import shared types, add Shape.period property, and delegate default generate_cad to shape_to_cad.
- Update Tpms and Spinodoid to set their intrinsic _period and reuse mesh_to_periodic_shell; remove duplicated periodic-sewing code.
- Add tests/tests_shapes/test_shape_period.py to verify period behavior and periodicity for Tpms/Spinodoid.

These changes centralize type annotations, avoid duplicated sewing logic, and expose intrinsic periodicity as a data-structure invariant used by TPMS/Spinodoid shapes. The periodic shell code requires the optional CAD backend.
Replace the single monolithic microgen/cad.py with a microgen.cad subpackage. The functionality has been split across new modules: __init__.py, _install.py, io.py, meshbridge.py, primitives.py, shape.py and topo.py to isolate responsibilities and enable lazy OCP imports (OCP remains an optional dependency). Tests were updated to reflect the package layout (no top-level OCP import). This reorganization improves maintainability and ensures import-time safety when OCP is not installed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant