You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The Lode-angle cutoff corrupts small nonhydrostatic stress round trips, reconstructed stresses can be misordered, and the compression-cap flow gradient lacks its theta component.
Extends GeoMechanics stress-state handling from (p, q) to (p, q, theta), carrying the Lode angle through principal-stress conversions and yield-surface evaluation.
Changes:
Replaces PQ with the three-component PQTheta type and updates its tests.
Adds Lode-angle calculation and inverse conversion to principal stresses.
Adds a Coulomb yield-value overload and migrates compression-cap interfaces to PQTheta.
The reason will be displayed to describe this comment to others. Learn more.
Hi Wijtze Pieter,
I've reviewed the extension of class PQ to PQTheta. In addition, I've used Copilot to attempt to find edge cases and other things that we didn't think of. Can you please see to what extent you agree/disagree with the comments/suggestions? After that, we can see how to make this draft PR ready to be merged into master, and how I can contribute to that. Thank you.
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether we should add a comment here that says Theta equals Lode angle. Also, would it be wise to make explicit that the returned angle is in radians?
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder to myself (found by Copilot): std::distance returns a signed value and msVectorSize is unsigned, so the comparison produces a sign-compare warning.
The reason will be displayed to describe this comment to others. Learn more.
Yet another useful remark by Copilot: CopyTo<VectorType> requires VectorType(size_t) and begin(). That works for Vector but not for array_1d or BoundedVector (the latter would break on the size argument). Constrain it with a concept, or drop it in favour of Values() plus a conversion.
The reason will be displayed to describe this comment to others. Learn more.
I've also requested Copilot to review these unit tests. I've instructed it to focus on functionality in the PQTheta class that is not properly covered. This was its response:
The suite covers nearly all of the class. A few behaviours are untested, and some tests are weaker than they look.
Coverage
Tested: default construction, construction from three values, construction from a vector (Vector, BoundedVector, std::vector), construction from a ublas expression, the debug-only size check, mutable accessors, CopyTo, += and +.
Gaps
Aliasing and independence in +=.
• stress_state += stress_state is untested. It works with std::ranges::transform, but it is the classic edge case.
• Add a check that the right-hand operand is unchanged after +=.
• Add a check that operator+ doesn't mutate its operands. Both are passed so that Lhs is a copy, so a regression to a reference parameter would go unnoticed.
Const accessors are barely distinguished.
• Most P(), Q() and Theta() reads go through temporaries or const auto objects, which does exercise the const overloads.
• PQTheta_ComponentsCanBeModifiedDirectly checks the mutators via Values() only.
• Add a check that the other components are untouched. The current asserts do cover that implicitly, so this one is minor.
No test that the Values() order matches P, Q, Theta. The 3-value constructor test checks the accessors but not Values(). The vector constructor test checks both, so ordering is covered. This one is minor.
Copy and move semantics. Copying and assigning a PQTheta is untested. They are defaulted, so low value.
The release-build gap is real.
• The size-mismatch test is skipped in non-debug builds.
• The release behaviour for a vector that is too long is a buffer overflow (the unchecked std::copy), and for one that is too short it leaves the remaining values at zero.
• Neither is tested. If you switch to KRATOS_ERROR_IF as I suggested earlier, the test can run in both modes.
CopyTo with a type it can't support. Only Vector, BoundedVector and std::vector are tested. BoundedVector<double,3>(3) works here, but array_1d would not compile. That is fine, since the test documents the supported set.
No negative or extreme values. Every value is positive. Add a negative-value case (stresses are often negative) to make sure nothing is clamped or abs'd.
Test quality
• The test names are good and the Arrange/Act/Assert structure is consistent.
• PQTheta_HasZeroesAsValuesWhenDefaultConstructed constructs three temporaries. A single named object would be cleaner.
• The expression test's comment is excellent, since it documents why the test exists.
• CanBeConstructedFromFromThreeValues has a typo ("FromFrom").
• The Exception type in the debug test is the generic one. It would be stronger to check the message, e.g. with KRATOS_EXPECT_EXCEPTION_IS_THROWN, which would also verify the "expected 3 values" text.
If I had to add only two tests: self-addition (x += x) and operand-preservation for operator+, then a negative-value case.
The reason will be displayed to describe this comment to others. Learn more.
I think we need to add at least one test that covers the calculation of the yield function value given a $(p, q, \theta)$ stress state, since an overload for it has been added. If you agree that we should extend the Coulomb yield surface with an overload for the calculation of the derivative of flow function given a $(p, q, \theta)$ stress state, then we'll also need a unit test for that.
The reason will be displayed to describe this comment to others. Learn more.
I've asked Copilot to check for any gaps in the test coverage of functions TransformPrincipalStressesToPQandTheta and TransformPQThetaToPrincipalStresses.
This was its response:
Coverage in test_stress_strain_utilities.cpp is thin. It has one test, for the forward direction only.
What exists
CheckTransformPrincipalStressesToPQandTheta uses σ = (30, 20, 10) and expects p = 20, q = √300, θ = 0. That is a single, symmetric, positive-stress case.
TransformPQThetaToPrincipalStresses has no direct test
• It is only exercised indirectly through CoulombYieldSurface (coulomb_yield_surface.cpp:145).
• If that indirect path is covered, only the yield function value is checked, and the individual principal stresses are not.
• A mistake in the phase shifts or amplitude could slip through if it happened not to affect the tested yield values.
Gaps in the forward test (σ → p, q, θ)
θ ≠ 0 is never checked here. Add these cases:
• Triaxial compression (θ = +30° for σ1 > σ2 = σ3).
• Triaxial extension (θ = −30° for σ1 = σ2 > σ3).
• An intermediate angle, e.g. θ = 15°.
• The sign of θ is the most error-prone part.
Hydrostatic state, e.g. (10, 10, 10). The expected result is q = 0 and θ = 0 via the q < 1e-12 branch, and CalculateLodeAngle has this special case.
Negative principal stresses, which are the realistic case in this application. The test has only positive values.
Unsorted input. Check what happens when the order is not descending. The current behaviour is undocumented.
Clamping near ±30°. The asin argument can exceed ±1 through round-off. A test at exactly θ = ±30° would exercise the clamp, because the argument is ≈ ±1.
Gaps in the reverse test (p, q, θ → σ)
This direction needs a test written from scratch:
• Pure hydrostatic: q = 0 gives σ = (p, p, p).
• θ = 0: σ = (p + (√3/3)·q, p, p − (√3/3)·q). For p = 20 and q = √300 that gives (30, 20, 10), the mirror image of the existing forward test.
• θ = ±30° (compression and extension).
• A negative p.
• Ordering of the result: σ1 ≥ σ2 ≥ σ3 for θ ∈ [−30°, 30°].
Round trip
Add a parameterised test checking Reverse(Forward(σ)) == σ for several sorted stress states, including negative values and the ±30° boundaries. It guards the consistency of the two conventions, which I verified analytically but which isn't pinned down by any test.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Replacing the small-q guard with q > 0 allows the diagonal stress vector {4e-109, 1e-109, 1e-109, 0} into this branch, where both the numerator and q³ underflow to zero. The resulting 0/0 produces NaN, which std::clamp cannot repair; the previous guard returned a finite angle. Normalize each deviatoric stress by q before multiplying to avoid dividing underflowed cubic quantities.
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
GeoMechanicsIssues related to the GeoMechanicsApplication
3 participants
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.
📝 Description
Extended PQ class to complete P, Q, Theta ( Lode angle ) class
Key changes