Skip to content

Comments

Feature/tensor#78

Draft
chemiskyy wants to merge 31 commits intomasterfrom
feature/Tensor
Draft

Feature/tensor#78
chemiskyy wants to merge 31 commits intomasterfrom
feature/Tensor

Conversation

@chemiskyy
Copy link
Member

This pull request introduces major improvements to the rotation and tensor mechanics infrastructure in the codebase, focusing on a new, comprehensive Rotation class with full Python and C++ support, enhanced documentation and examples, and the integration of the Fastor tensor library for efficient tensor operations. The changes modernize the rotation API, provide seamless interoperability with scipy.spatial.transform.Rotation, and introduce robust conversion utilities between Armadillo and Fastor tensors.

Rotation and Tensor Mechanics Enhancements:

  • Introduced a new Rotation class (Python and C++) that inherits from scipy.spatial.transform.Rotation, providing a unified and numerically stable interface for 3D rotations, SLERP interpolation, and direct Voigt notation operations. This includes support for various Euler angle conventions, intrinsic/extrinsic modes, and full Python bindings with NumPy integration. Extensive new and updated examples demonstrate usage and interoperability with SciPy, including batch operations and interpolation. [1] [2] [3] [4]

  • Added a new C++ header fastor_bridge.hpp providing efficient, zero-copy conversion utilities between Armadillo matrices and Fastor tensors, as well as Voigt-to-tensor and tensor-to-Voigt mappings and push-forward/pull-back operations for 4th-order tensors. This sets the stage for improved performance and maintainability in tensor mechanics code.

Build System Integration:

  • Integrated the Fastor library as a header-only dependency via CMake, ensuring it is available for tensor operations throughout the codebase. Fastor's include directory is now added as a system header for the main target. [1] [2]

Documentation Improvements:

  • Major updates and restructuring of documentation to reflect the new rotation API: added new sections and overviews for the Rotation module, updated function references and descriptions, and included a "What's New" section for Simcoon 2.0. Documentation now clearly distinguishes between the maths and rotation modules and highlights new features and usage patterns. [1] [2] [3] [4] [5]

Introduce a new Rotation subsystem: adds a C++ Rotation class (include/.../rotation_class.hpp and src/Simulation/Maths/rotation_class.cpp) implementing quaternion-based 3D rotations, Voigt operations, Euler conventions, SLERP, and apply methods for vectors/tensors. Add Python bindings (pybind11) and headers in simcoon-python-builder, update its CMake to build the rotation_class wrapper, and extend the python module registration. Add comprehensive documentation pages (continuum mechanics and C++ API) and index updates. Include a unit test (test/Libraries/Maths/TRotationClass.cpp) and adjust top-level CMakeLists where needed. This patch adds rotation functionality, docs, bindings, and tests to enable quaternion-based rotation operations from C++ and Python.
Add input validation helpers in the Python wrapper (validate_vector_size, validate_matrix_size) and apply them to rotation bindings to ensure correct array shapes. Add SciPy interoperability: Rotation.from_scipy and to_scipy methods with docs and conversions via quaternions. Replace uses of legacy sim_pi/sim_iota with simcoon::pi and simcoon::iota across Rotation implementation and update tests accordingly to use the centralized constants. This improves robustness of the Python API and unifies constant usage in the core code and tests.
Expand rotation Python docs with Scipy interoperability, active vs passive rotation conventions, input validation guidance, and notes on quaternion equivalence. Fix cross‑references in C++ API docs to point to the correct continuum_mechanics doc pages. Rename test file to Trotation_class.cpp, update CMakeLists, and add comprehensive Rotation unit tests (tensor/stiffness/compliance behavior, factory methods, Euler conventions, round‑trip and gimbal‑lock cases) to improve coverage and verify correctness.
Rename ambiguous as_QS/as_QE to explicit as_voigt_stress_rotation/as_voigt_strain_rotation and add apply_localization_strain/apply_localization_stress to Rotation API. Update implementation, header, Python bindings, documentation and tests to use the new names and to expose rotation of localization tensors (QE·A·QS^T and QS·B·QE^T). Refactor callers (ellipsoid_multi, state_variables*, etc.) to use Rotation::from_euler and the new apply_* methods instead of ad-hoc rotate_* helpers; add necessary includes and input validation for 6×6 tensors. Add unit tests verifying consistency with existing fillQS/fillQE/rotateA/rotateB functions and update docs to reflect the new API and examples.
Remove default values for Euler convention and active/passive flags across rotation APIs and pybind bindings to force callers to specify convention and mode. Updated C++ headers (rotation.hpp, rotation_class.hpp) and Python wrappers to make conv and active mandatory, adjusted pybind registrations in python_module.cpp and rotation_class.cpp, and updated tests (Trotation.cpp) to pass explicit arguments. Also add simcoon_docs rotation docstrings (doc_rotation.hpp) and hook them into module definitions for improved Python documentation.
Docs updated to remove references to a "default" Euler convention and require the convention to be specified in examples. In rotation.cpp, the previous behavior of printing an error and falling back to default axes has been replaced with throwing std::invalid_argument when an invalid Euler convention is supplied (message lists supported conventions). This enforces explicit, valid conventions and prevents silent fallback. Affected files: docs/continuum_mechanics/functions/doc_rotation.rst, docs/cpp_api/simulation/rotation.rst, src/Simulation/Maths/rotation.cpp.
Rename and reorganize rotation-related documentation to match updated API names and types. Key changes:
- Replace old function names with clearer ones: rotateL/rotateM -> rotate_stiffness/rotate_compliance; apply_localization_* -> apply_*_concentration; rotate_l2g_*/g2l_* functions replaced by *_R and *_angle variants.
- Update free-function autodoc/doxygen entries and Python autofunction names accordingly.
- Change C++ include references from rotation_class.hpp to rotation.hpp and document new Rotation construction functions (Rotation::from_euler, Rotation::from_axis_angle).
- Update examples to use Rotation::from_euler or pass a Rotation matrix to free functions.
These edits align the docs with the refactored rotation API and clarify naming (strain/stress concentration vs localization).
Rename and reorganize rotation-related Python wrappers and docs for clarity and vectorized usage. Replaced legacy fillR/fillQS/fillQE and rotateL/M/A/B/l2g/g2l APIs with clearer functions (rotate_stiffness_*, rotate_compliance_*, rotate_strain_concentration_*, rotate_stress_concentration_*, rotate_strain_*, rotate_stress_*), updated wrapper implementations to use descriptive variable names and support batched (ndim==2) inputs, and adjusted Rotation class method names (apply_localization_* -> apply_*_concentration). Also updated example docs to use simcoon.Rotation.from_axis_angle(...). Modified files: include/docs/Libraries/Maths/doc_rotation.hpp, include/simcoon/python_wrappers/Libraries/Maths/rotation.hpp, src/python_wrappers/Libraries/Maths/rotation.cpp, src/python_wrappers/Libraries/Maths/rotation_class.cpp, src/python_wrappers/python_module.cpp.
Introduce a unified Rotation class into rotation.hpp (merged from the removed rotation_class.hpp) providing quaternion-based factories, conversions, and apply methods for vectors, tensors and Voigt-notation quantities. Rename and refactor many legacy free functions (fillR / fillQS / fillQE / rotateL / rotateM / rotateA / rotateB / etc.) to clearer APIs (rotate_vec/rotate_mat, rotate_stress, rotate_strain, rotate_stiffness, rotate_compliance, rotate_strain_concentration, rotate_stress_concentration, etc.). Update the Python example to use sim.Rotation.from_axis_angle / from_euler and the new rotate_* function names. Remove the standalone rotation_class header and corresponding legacy sources to consolidate rotation functionality; this is a breaking API change that modernizes rotation handling and exposes richer functionality (quaternions, Euler, rotvec, Voigt helpers, slerp, composition, etc.).
Replace legacy rotation helpers with the new Rotation class methods across the codebase and tests. Updates include: using Rotation::from_euler / from_matrix and its apply_* helpers (apply_stiffness, apply_compliance, apply_strain/apply_stress, apply_strain_concentration/apply_stress_concentration) instead of free functions like rotateL, rotateM, rotateA, rotate_g2l_L, rotate_g2l_stress, rotate_l2g_A, fillR, fillQE/QS, etc. Remove includes of rotation_class.hpp where no longer needed. Adjusted unit tests to construct expected rotations via the Rotation API and to validate transformations by applying rotations to vectors/matrices rather than calling the old utility functions. Changes touch continuum mechanics, homogenization, micromechanics schemes, phase state variables, and math tests to unify on the new rotation interface and improve consistency.
Remove the legacy Python bindings and documentation for the standalone rotation free-functions and migrate examples/docs to use the Rotation class API.

Changes:
- Docs: updated docs/continuum_mechanics/functions/doc_rotation.rst and docs/cpp_api/simulation/rotation.rst to remove free-function sections and emphasize the Rotation class.
- Examples: examples/continuum_mechanics/rotation.py rewritten to use simcoon.Rotation (from_axis_angle/from_euler and apply/apply_tensor/apply_stress/etc.) instead of the rotate_* free functions.
- Python bindings: deleted simcoon-python-builder/include/simcoon/docs/Libraries/Maths/doc_rotation.hpp, include/simcoon/python_wrappers/Libraries/Maths/rotation.hpp and src/python_wrappers/Libraries/Maths/rotation.cpp; removed their registration from python_module.cpp.
- Build: simcoon-python-builder/CMakeLists.txt no longer compiles src/python_wrappers/Libraries/Maths/rotation.cpp.

Rationale: consolidate the public Python API around the object-oriented Rotation class and remove duplicated/free-function Python wrappers while keeping the Rotation class binding and C++ API intact.
Rename the Rotation pybind11 wrapper files and update references: rotation_class.hpp -> rotation.hpp and rotation_class.cpp -> rotation.cpp. Rename the registration function register_rotation_class -> register_rotation and update its declaration, definition, includes, and the call in python_module.cpp. Update CMakeLists.txt to build src/python_wrappers/Libraries/Maths/rotation.cpp. This unifies the wrapper naming and keeps module registration consistent.
Make simcoon.Rotation a subclass of scipy.spatial.transform.Rotation and add full scipy interoperability. Adds a pure-Python simcoon.rotation.Rotation wrapper that inherits scipy Rotation and delegates mechanics operations (apply_stress/strain/stiffness/etc.) to the C++ backend via a new _CppRotation interface. The C++ pybind wrapper was adjusted to expose simcoon::Rotation as _CppRotation and to accept plain scipy-like Rotation objects (duck-typed via as_quat) for composition, slerp and equality. Updated package metadata to require scipy, refreshed docs and examples to use scipy Euler conventions and show interoperability, and added comprehensive tests for type identity, mechanics methods, scipy upgrades, and C++ handling of scipy objects. Also import Rotation in __init__ to override the star-imported C++ class.
Declare and populate the Fastor dependency using FetchContent (pointing to the master branch). As Fastor is header-only, no build step is performed — FetchContent_Populate is used and the source dir is printed for visibility. The Fastor include path is added to the simcoon target as SYSTEM PUBLIC (via $<BUILD_INTERFACE:${fastor_SOURCE_DIR}>) to consume the headers and suppress warnings.
Introduce include/simcoon/Continuum_mechanics/Functions/fastor_bridge.hpp providing conversion and utility helpers between Armadillo and Fastor tensor types. Adds a voigt_map constant and functions: zero-copy arma_to_fastor2 (const and non-const), fastor2_to_arma, voigt_to_fastor4, fastor4_to_voigt (stiffness/Voigt convention), and push_forward_4 / pull_back_4 for 4th-order tensor transforms. Header includes license boilerplate and documents column-major zero-copy for 3x3 matrices and the minor-symmetry handling used in Voigt conversions.
Introduce Python bindings for simcoon continuum-mechanics tensors. Adds header declare register_tensor and implementation that registers VoigtType and Tensor4Type enums and two internal classes (_CppTensor2, _CppTensor4) via pybind11. The bindings provide constructors, static factories (from_mat, from_voigt, zeros, identity, etc.), properties (mat, voigt, vtype/type), methods (rotate, push_forward, pull_back, contract), arithmetic operators, and __repr__ implementations. Includes numpy input validation helpers and conversions using carma/armadillo and depends on existing simcoon C++ tensor and Rotation types to expose C++ tensor functionality to Python.
Add new src/Continuum_mechanics/Functions/tensor.cpp implementing tensor2 and tensor4 types. Provides constructors, Voigt conversions, Fastor/Armadillo bridges, rotation, push-forward/pull-back, contraction, dyadic operations, Mises/dev/trace helpers, and arithmetic operators. Includes Fastor caching and conversion utilities to accelerate 4th-order tensor ops and integrates with existing Rotation/constitutive helpers for continuum mechanics use.
@github-project-automation github-project-automation bot moved this to Backlog in simcoon 2.0 Feb 13, 2026
@chemiskyy chemiskyy marked this pull request as draft February 13, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant