Skip to content

Commit

Permalink
Merge pull request #280 from gridap/add_cross_product_for_VectorValues
Browse files Browse the repository at this point in the history
Added cross product operation for vectors
  • Loading branch information
fverdugo authored Jun 12, 2020
2 parents c4cab0d + cfbb71d commit 8b5905d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Operator `` (\otimes) as an alias of `outer`. Since PR [#239](https://github.com/gridap/Gridap.jl/pull/239).
- Support for (symmetric) 4th order tensors. Since PR [#239](https://github.com/gridap/Gridap.jl/pull/239).
- Optimizations for symmetric 2nd order tensors. Since PR [#239](https://github.com/gridap/Gridap.jl/pull/239).
- Methods for `cross` function (aka `×` (\times)) to operate with `VectorValues`.
Since PR [#280](https://github.com/gridap/Gridap.jl/pull/280).

### Changed

Expand Down
15 changes: 14 additions & 1 deletion src/TensorValues/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ end

const = outer

###############################################################
# Cross Product
###############################################################

function cross(a::MultiValue{Tuple{3}}, b::MultiValue{Tuple{3}})
VectorValue{3}(a[2]b[3]-a[3]b[2], a[3]b[1]-a[1]b[3], a[1]b[2]-a[2]b[1])
end

function cross(a::MultiValue{Tuple{2}}, b::MultiValue{Tuple{2}})
a[1]b[2]-a[2]b[1]
end

cross(a::MultiValue,b::MultiValue) = error("Cross product only defined for R2 and R3 vectors")

###############################################################
# Linear Algebra
###############################################################
Expand Down Expand Up @@ -450,4 +464,3 @@ for op in (:inner,:outer)#,:(:))
($op)(a::Function, b::GridapType) = operate($op,a,b)
end
end

20 changes: 20 additions & 0 deletions test/TensorValuesTests/OperationsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ c = outer(e,k)

@test tr(c) == VectorValue(50,110)

# Cross product

a = VectorValue(1,2,3)
b = VectorValue(3,1,6)
c = VectorValue(9,3,-5)
@test a × b == c

a = VectorValue(2,3)
b = VectorValue(5,2)
@test a × b == -11

a = VectorValue(1.0,5.0,-4.0)
b = VectorValue(6.0,2.0,3.0)
c = VectorValue(23.0,-27.0,-28.0)
@test cross(a, b) == c

a = VectorValue(4.0,1.0)
b = VectorValue(3.0,-2.0)
@test cross(a, b) == -11.0

# Linear Algebra

t = TensorValue(10,2,30,4,5,6,70,8,9)
Expand Down

0 comments on commit 8b5905d

Please sign in to comment.