Skip to content

Cache rotation operators with frame_rotation - #130

Merged
chemiskyy merged 4 commits into
masterfrom
feature/cached-phase-rotation
Oct 6, 2026
Merged

chemiskyy merged 4 commits into
masterfrom
feature/cached-phase-rotation

Conversation

@chemiskyy

Copy link
Copy Markdown
Member

Introduce frame_rotation to precompute and store 3x3 and 6x6 Voigt rotation operators (and their inverses) so rotations are applied with a single matrix product instead of rebuilding operators every call. Make frame_rotation immutable and provide factory from Euler angles. Update material_characteristics to hold a cached frame() (rebuilding when angles change). Change state_variables and derived classes to accept a frame_rotation for rotate_l2g/rotate_g2l and apply the cached strain/stress/stiffness/tensor operators (using inverse flags for g->l). Update phase_characteristics to use material_characteristics::frame(). Add tests verifying frame_rotation matches Rotation::apply_* bitwise. Minor includes and headers adjusted accordingly.

Introduce frame_rotation to precompute and store 3x3 and 6x6 Voigt rotation operators (and their inverses) so rotations are applied with a single matrix product instead of rebuilding operators every call. Make frame_rotation immutable and provide factory from Euler angles. Update material_characteristics to hold a cached frame() (rebuilding when angles change). Change state_variables and derived classes to accept a frame_rotation for rotate_l2g/rotate_g2l and apply the cached strain/stress/stiffness/tensor operators (using inverse flags for g->l). Update phase_characteristics to use material_characteristics::frame(). Add tests verifying frame_rotation matches Rotation::apply_* bitwise. Minor includes and headers adjusted accordingly.
Change frame_rotation to perform in-place rotations with fixed-size Armadillo types: add rotate_strain/rotate_stress/rotate_stiffness/rotate_tensor that mutate their arguments and store 6x6 fixed Voigt operators and 3x3 fixed rotation matrices to avoid heap temporaries. Update all callers (state_variables, state_variables_M, state_variables_T and tests) to use the new in-place API and adjust which fields are copied/rotated between local/global copies with clarifying comments. Tests updated to validate bitwise-equivalent behavior and inverse undoing of rotations.
Refactor frame_rotation to materialize fixed-size Voigt operators once (stored in an operators struct) and apply them in-place via a pick(inverse) accessor. Avoid rebuilding operator matrices per call, special-case identity as a no-op, and reorder multiplications to prevent heap temporaries. material_characteristics now eagerly builds/copies the frame via build_frame() (removed the mutable/valid flag approach) so the frame operators are set when angles are assigned or copied. state_variables and the M/T specializations: document which members cross frames and why, always call frame.rotate_* (frame handles identity), and normalize Voigt vector/matrix shape handling using vectorise/reshape for dSdT/drdE. Minor test rename to match project naming. Overall this reduces allocations, clarifies ownership/transfer semantics, and improves performance and thread-safety for repeated UMAT calls.
Replace bool "inverse" parameters with a typed direction enum (forward/inverse) for frame_rotation rotate_* APIs and internal pick() calls. Introduce apply6 helper to centralize fixed-size vector ops and tighten size checks; preserve identity no-op behavior. Update callers across state_variables and phase implementations to use the new enum. material_characteristics: store the angles used to build the cached frame, initialize them in ctors/assignment, rebuild frame via build_frame(), and enforce consistency by throwing std::logic_error if public angle members were changed directly (encouraging use of update()). Adjust thermomechanical rotation semantics for drdE/dSdT to use the stress operator and keep shape. Add tests and CMake entries: new Phase test for material frame, update rotation tests and Python tests to validate oriented/unoriented invariance. Also add a few needed includes (algorithm, stdexcept).
@chemiskyy
chemiskyy merged commit 99113c3 into master Oct 6, 2026
7 checks passed
@chemiskyy
chemiskyy deleted the feature/cached-phase-rotation branch October 6, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant