Added method for gradientSymTensor - #127
Conversation
Cyclomatic Complexity CheckL 97 (C 22-41): The McCabe cyclomatic complexity of 'initialiseSensorData' is 19. L 59 (C 14-17): The McCabe cyclomatic complexity of 'curl' is 2. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #127 +/- ##
===========================================
- Coverage 100.00% 98.36% -1.64%
===========================================
Files 59 48 -11
Lines 911 1102 +191
===========================================
+ Hits 911 1084 +173
- Misses 0 18 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| % components are [sxx] in 1D, [sxx, syy, sxy]' in 2D and | ||
| % [sxx, syy, szz, sxy, sxz, syz]' in 3D. |
There was a problem hiding this comment.
We should use the standard Voigt notation order here unless there is a good reason not to, which is [s11, s22, s33, s23, s13, s12] or [sxx, syy, szz, syz, sxz, sxy]. (This will change the indexing used later on.)
There was a problem hiding this comment.
Thanks for the suggestion! The reason I did not adopt the Voigt notation was that it made it less intuitive (at least as an initial thought) to apply the Einstein notation in a loop in the solver (see this line).
In the loop, using the indices for i = 1 j = 2
| @@ -0,0 +1,176 @@ | |||
| %% gradientSymTensor | |||
There was a problem hiding this comment.
The operation we're applying here is actually the divergence of a tensor, but in this case, we're keeping the split components. So I'd call this divergenceSplitTensor (similar in spirit to divergenceSplit).
For completeness, we can also write a divergenceTensor which just calls divergenceSplitTensor and then sums the components over the 5th dimension, leaving a vector field (see also divergence).
I would leave out the sym part in the function name. Later we could add support for non-symmetric tensors, where the input is given as a Tensor (rather than a vector with the components in Voigt notation). The output will be the same size.
The docs will need updating (where you write gradient).
There was a problem hiding this comment.
Sounds good! Thanks for that. I will address the comments and the name change at the same time next chance I get.
I think what threw me off here is equation (7a) in the IEEE paper and I just didn't pay enough attention to the maths.
(1) Calculate the spatial gradients of the stress field using the Fourier collocation spectral method.
There was a problem hiding this comment.
I have applied this change. Please carefully read through the description as I may have gotten the terminology wrong.
Also note that I didn't (yet) add the methods that will sum-up the components to a vector. I will get around to that in the near future, but first I wanted to make sure what's here is correct. I'm not sure if we should use the split directly in the solver or use the summed version due to the multi-axisal pml - I will look into that as soon as I can.
| case 3 | ||
| % Indecies for the symmetric (squashed) stress tensor are | ||
| % different in 2D and 3D so the spatial derivatives for the | ||
| % dxy components need overwritten with the correct |
There was a problem hiding this comment.
I would handle the case statement so that you don't have to compute these twice (the FFTs are expensive and this operation is done many times). Same for below for case with ND k-space correction.
There was a problem hiding this comment.
Very good point! I'll address this by the weekend as soon as I find some time.
There was a problem hiding this comment.
I used an if statement inside the case 2 statement. This is a simple solution but I think it would work as it is outside the internal loops over the grid points.
| dsxxdx = obj.ddxShiftPos; | ||
| dsxydy = obj.ddyShiftNeg; | ||
| dsxzdz = obj.ddzShiftNeg; | ||
| dsxydx = obj.ddxShiftNeg; | ||
| dsyydy = obj.ddyShiftPos; | ||
| dsyzdz = obj.ddzShiftNeg; | ||
| dsxzdx = obj.ddxShiftNeg; | ||
| dsyzdy = obj.ddyShiftNeg; | ||
| dszzdz = obj.ddzShiftPos; |
There was a problem hiding this comment.
Noting that the off-diagonal components are duplicated, but I can't think of a nice notation to combine them, and it shouldn't have any performance or memory consequences anyway.
There was a problem hiding this comment.
Do you mean that obj.ddxShiftNeg is called twice, once for dsxydx and once for dsxzdx (and the same for the y and z components)? The other option is to set dsxzdx = dsxydx then, but I'm not sure I like that either.
See issue #124 for description and #120 for the solver that requires this method.
The PR is made with awareness that the API might have to change. It is also worth exploring the further use of the gradient of a symmetric tensor operator as I'm not sure if it will be required for any other solvers.