Repository navigation
Cache rotation operators with frame_rotation - #130
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.