Skip to content

Refactor/rve#140

Open
chemiskyy wants to merge 3 commits into
mainfrom
refactor/rve
Open

Refactor/rve#140
chemiskyy wants to merge 3 commits into
mainfrom
refactor/rve

Conversation

@chemiskyy
Copy link
Copy Markdown
Member

This pull request introduces several improvements and refactorings to the microgen codebase, focusing on enhancing the Rve class, improving surface mesh generation for shapes, and maintaining clean import boundaries for optional dependencies. The most significant changes include making Rve immutable and more robust, updating mesh generation methods for greater flexibility, and adding a lint-style test to enforce import constraints.

Rve class improvements:

  • Refactored Rve to be a frozen dataclass, making it immutable and thread-safe. Added validation helpers for its parameters, new properties for min_point and max_point, and a new grid() method for generating structured grids aligned with the RVE. The constructor now supports periodic boundary condition flags, and a more robust from_min_max constructor was added. ([[1]](https://github.com/3MAH/microgen/pull/140/files#diff-d871fe5a64aa369935f17dce4cd4c4f7213c9c965ce1841732e5d33f5e696e01L3-R14), [[2]](https://github.com/3MAH/microgen/pull/140/files#diff-d871fe5a64aa369935f17dce4cd4c4f7213c9c965ce1841732e5d33f5e696e01L19-R162))
  • Improved input validation for center, dim, and pbc parameters in Rve, with clear error messages and support for various input types. ([microgen/rve.pyL19-R162](https://github.com/3MAH/microgen/pull/140/files#diff-d871fe5a64aa369935f17dce4cd4c4f7213c9c965ce1841732e5d33f5e696e01L19-R162))

Surface mesh generation flexibility:

  • Updated generate_surface_mesh methods in Box, Sphere, and Spinodoid to accept bounds and resolution parameters. When these are provided, the methods fall back to the base implementation, allowing polymorphic callers to request specific sampling, otherwise using the native PyVista mesh. ([[1]](https://github.com/3MAH/microgen/pull/140/files#diff-c227cea663f04fbc41b04b36b599dab1ec943df83f886a2a33b2cb0d4e68cc84R109-R126), [[2]](https://github.com/3MAH/microgen/pull/140/files#diff-a0646891e8c15a45af285eb3b34d22c1471f0e2d500596d51d9bad049d38a9d3R82-R100), [[3]](https://github.com/3MAH/microgen/pull/140/files#diff-d4d99a42f3f33d721a232441455fe4b2781c7eadf3b3928b75ebf3343ea75556R219-R235))

API and import/export maintenance:

  • Added new shapes (GradedInfill, Sweep) to the public API in microgen/__init__.py and microgen/shape/__init__.py, ensuring they are accessible as top-level imports. ([[1]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846R39), [[2]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846R51), [[3]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846R80), [[4]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846R96), [[5]](https://github.com/3MAH/microgen/pull/140/files#diff-024071544e6e765768b16b31822ce0d8281e1f283764ef04d85e614b23c1672fL51-R51), [[6]](https://github.com/3MAH/microgen/pull/140/files#diff-024071544e6e765768b16b31822ce0d8281e1f283764ef04d85e614b23c1672fR165), [[7]](https://github.com/3MAH/microgen/pull/140/files#diff-024071544e6e765768b16b31822ce0d8281e1f283764ef04d85e614b23c1672fR177))
  • Removed the unused rotate_pv_euler function from both the code and the public API. ([[1]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846L20), [[2]](https://github.com/3MAH/microgen/pull/140/files#diff-9eae507ca7aca3774110b95b4c1d94be6defba96ce1b3864edb9f133d7ab8846L120), [[3]](https://github.com/3MAH/microgen/pull/140/files#diff-663e8d6f8a6794e0262c63d472ccfd5a707f973570dc7304e33508cf97dad97cL129-L161))

Dependency management and testing:

  • Added a lint-style test (tests/test_no_top_level_ocp_imports.py) to ensure that top-level imports of the optional OCP dependency only occur within the CAD boundary, preventing accidental import errors for users not installing CAD extras. ([tests/test_no_top_level_ocp_imports.pyR1-R88](https://github.com/3MAH/microgen/pull/140/files#diff-36aaedd6993eff5e45adb5c160afaec6aafa53661ada94663c1e7c29f63da346R1-R88))

Type hints and code clarity:

  • Improved type annotations for shape modules, especially for BoundsType and related imports, enhancing code clarity and type checking. ([[1]](https://github.com/3MAH/microgen/pull/140/files#diff-c227cea663f04fbc41b04b36b599dab1ec943df83f886a2a33b2cb0d4e68cc84R24), [[2]](https://github.com/3MAH/microgen/pull/140/files#diff-a0646891e8c15a45af285eb3b34d22c1471f0e2d500596d51d9bad049d38a9d3R21), [[3]](https://github.com/3MAH/microgen/pull/140/files#diff-d4d99a42f3f33d721a232441455fe4b2781c7eadf3b3928b75ebf3343ea75556R37))

These changes collectively improve the robustness, flexibility, and maintainability of the microgen codebase.

chemiskyy added 3 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.
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