-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3-Tensor Operations and Constructors #415
Conversation
Added functionality to compute ``` a_ij = b_kij*c_k a_i = b_ijk*c_jk ```
Codecov Report
@@ Coverage Diff @@
## master #415 +/- ##
==========================================
+ Coverage 87.26% 87.32% +0.05%
==========================================
Files 158 158
Lines 11094 11170 +76
==========================================
+ Hits 9681 9754 +73
- Misses 1413 1416 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Omega-xyZac thanks for your PR.
I have added some coments to be addressed (see inline).
In addition:
- Please, add some test for the new functionality in test/TensorValuesTests/OperationsTests.jl
- Before merging this, please clarify what is causing the you reported in issue 3-tensor contractions with 2-tensor and 1-tensor #414
- This new functionality calculates `a_ijpm = b_ijkl*c_jkpm` and also provides testing. - I have re-enabled use of `:` operator since this is the most suitable.
I guess we need a new symbol instead of |
Sure @Omega-xyZac ! Perhaps we can use ⊡ (\boxdot) In addition, try to respect our convention in which the indices that are contracted are the ones that are in "contact". That is: a = b ⊡ c # a_ijkl = b_ijab*c_abkl This convention is important since products with tensors are not always commutative. |
Ah yes sorry! That was actually a typo in the comment. The new |
- Also changed comment to correctly reflect computation
Why do we introduce a new symbol for the double contraction of tensors? There is a standard symbol for this and it is : . I would keep : unless there is a very compelling reason. |
I agree but there seems to be issues with |
@santiagobadia the symbol : has a very concrete meaning in julia (range). I find very confusing to give it another meaning. |
There is not going to be any clash between these two cases. The problem is that the precedence of : vs +,- is different between these two cases. Probably, this cannot be fixed. That is a compelling reason. So 👍 with the new symbol. |
Hi all, The others are
|
The last operations are single and double contractions. You can add them and use the agreed symbols. I would not include the one that breaks the rules in Gridap. I don't think this is standard enough. You can define them in your part. |
We could probably consider also this notation... ⋅¹,⋅²,⋅³,⋅⁴,... # n-contractions
⋅¹ == ⋅
⋅² == ⊡ I guess we will need 4-contractions of 4-tensors, which are usually expressed as What do you think @fverdugo @Omega-xyZac ? |
This is probably the best solution to the problem of higher order contractions. |
src/TensorValues/Operations.jl
Outdated
@@ -220,8 +246,40 @@ function inner(a::SymFourthOrderTensorValue{D},b::MultiValue{Tuple{D,D}}) where | |||
inner(a,symmetric_part(b)) | |||
end | |||
|
|||
# a_i = b_ijk*c_jk | |||
@generated function inner(a::A, b::B) where {A<:MultiValue{Tuple{D1,D2,D3}},B<:MultiValue{Tuple{D2,D3}}} where {D1,D2,D3} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an inner product. This is a double contraction, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I was trying to follow the convention that has been used in the rest of the file. I'll update these with the above notation
src/TensorValues/Operations.jl
Outdated
############################################################### | ||
|
||
# a_ijpm = b_ijkl*c_klpm | ||
@generated function ⊡(a::A, b::B) where {A<:SymFourthOrderTensorValue{D},B<:SymFourthOrderTensorValue{D}} where D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would give a name to this method, e.g., double_contraction
and then define the symbol, as we do, e.g., for dot
.
Added ``` # a_ilm = b_ijk*c_jklm # a_ilm = b_ij*c_jlm # a_il = b_ijk*c_jkl # a_il = b_ij*c_jl ``` Implemented notation per S. Badia: ``` ⋅¹,⋅²,⋅³,⋅⁴,... # n-contractions ⋅¹ == ⋅ ⋅² == ⊡ ```
Noticed this in the build doc
I think this is due to lines 339,340, and 598-606. Is this the correct way to be doing this? Perhaps |
I dont know if these names are going to be interpreted as operators by the julia compiler |
This seems to be working so far in my testing and other code. |
#416 addressed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some more comments (see inline)
Note that ⋅²
and ⊡
are the same. I would only keep one version, perhaps ⋅²
. On the other hand, having double_contraction
is fine since it is the plain asci version.
# a_ijpm = b_ijkl*c_klpm | ||
@generated function double_contraction(a::A, b::B) where {A<:SymFourthOrderTensorValue{D},B<:SymFourthOrderTensorValue{D}} where D | ||
|
||
Sym4TensorIndexing = [1111, 1121, 1131, 1122, 1132, 1133, 2111, 2121, 2131, 2122, 2132, 2133, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is particular for 3D. Can you implement it in general?
If for performance reasons, you want to keep the 3D specialization then use the signature
function double_contraction(a::A, b::B) where {A<:SymFourthOrderTensorValue{3},B<:SymFourthOrderTensorValue{3}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, perhaps ⋅²
. I will keep the 3D version since this should be fairly quick. I will have to have a think about how to do this generally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might do the trick:
@generated function double_contraction(a::SymFourthOrderTensorValue{D}, b::SymFourthOrderTensorValue{D}) where D
str = ""
for j in 1:D
for i in j:D
for m in 1:D
for p in m:D
s = ""
for k in 1:D
for l in 1:D
s *= " a[$i,$j,$k,$l]*b[$k,$l,$p,$m] +"
end
end
str *= s[1:(end-1)]*", "
end
end
end
end
Meta.parse("SymFourthOrderTensorValue{D}($str)")
end
Need to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, keep ⋅² so we use the same notation for all >1 contractions.
- Added generalised contraction. - Removed ⊡.
@Omega-xyZac can you include some comment on the new functionality in the https://github.com/gridap/Gridap.jl/blob/master/NEWS.md file ? Please add the comments in a new section called
Thanks! |
Added functionality to compute