materials: build the deviatoric projector once, not per call (#77) - #80
Merged
Merged
Conversation
Both generic yield-function policies constructed the rank-4 IIdev inside
flow_normal_stress_derivative(), which runs once per plastic step:
const tensor4 IIdev{plasticity_detail::make_IIdev<T, Dim>()};
IIdev depends on nothing but T and Dim. Measured at -O2 -DNDEBUG, building
it costs 149 ns against 2.6 ns to read a cached one, and it was worth
15-22% of a plastic step:
drucker_prager_plasticity 700 ns -> 548 ns (-22%)
j2_rk_plasticity(implicit_euler) 971 ns -> 759 ns (-22%)
j2_rk_plasticity(sdirk3) 1119 ns -> 953 ns (-15%)
j2_plasticity had always cached it in a member, which is most of why its
plastic step was 3-6x cheaper than the two materials that go through the
policies. This brings them to the same standard.
A function-local static rather than a member: the policies are value types
that get copied around, so one instance is shared by every material at
that (T, Dim). Initialization is thread safe, which matters because the
UMAT layer runs one context per thread; after the first call only the
guard check remains, and that is inside the 2.6 ns above.
Stress and tangent are unchanged -- the existing J2, Drucker-Prager and
RK value assertions all still pass.
petlenz
force-pushed
the
perf/cached-iidev
branch
from
September 20, 2026 09:32
92267b3 to
c9f05ef
Compare
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.
Closes #77.
Both generic yield-function policies constructed the rank-4
IIdevinsideflow_normal_stress_derivative(), which runs once per plastic step:const tensor4 IIdev{plasticity_detail::make_IIdev<T, Dim>()};It depends on nothing but
TandDim.Measured
-O2 -DNDEBUG, paired/interleaved timing (from the performance review on #77):make_IIdev<double,3>()drucker_prager_plasticityj2_rk_plasticity(implicit_euler)j2_rk_plasticity(sdirk3)j2_plasticityhad always cached it in a member, which is most of why its plastic step was 3-6x cheaper than the two materials that go through the policies. This brings them to the same standard.Why a function-local static
The policies are value types that get copied around, so a member would be rebuilt per copy. This way one instance is shared by every material at that
(T, Dim). Initialization is thread safe, which matters because the UMAT layer runs one context per thread; after the first call only the guard check remains, and that is inside the 2.6 ns above.Correctness
Stress and tangent are unchanged -- the existing J2, Drucker-Prager and RK value assertions all still pass. 311/311.