Skip to content

Promote before constructing #26

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

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ end
# Constructors
for T in (:EngineeringStress, :EngineeringStrain)
@eval begin
$T(data::AbstractVector) = $T(MVector{6}(data))
$T(values...) = $T(vec(values))
$T(data::AbstractVector) = $T(MVector{6}(promote(data...)))
$T(values...) = $T(collect(values))
end
end
for (T, N) in
zip((:TensorStress, :TensorStrain, :StiffnessMatrix, :ComplianceMatrix), (3, 3, 6, 6))
@eval begin
$T(data::AbstractMatrix{S}) where {S} = $T{S}(MMatrix{$N,$N}(data))
$T(data::AbstractMatrix{S}) where {S} = $T{S}(MMatrix{$N,$N}(promote(data...)))
$T(values...) = $T(SymmetricSecondOrderTensor{$N}(values...))
end
end
for T in (:StiffnessTensor, :ComplianceTensor)
@eval $T(data::AbstractArray{S,4}) where {S} =
$T{S}(SymmetricFourthOrderTensor{3}(data))
$T{S}(SymmetricFourthOrderTensor{3}(promote(data...)))
end

Base.size(::Type{<:TensorVariable}) = (3, 3)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using LinearElasticityBase
using Test

@testset "LinearElasticityBase.jl" begin
include("types.jl")
include("similar.jl")
include("operations.jl")
include("invariants.jl")
Expand Down
6 changes: 6 additions & 0 deletions test/types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@testset "Promote all values before constructing types (#25)" begin
e = EngineeringStrain([j == 1 ? 0.005 : 0 for j in 1:6])
@test eltype(e) == Float64
e = EngineeringStrain([j == 1 ? 1//2 : 0 for j in 1:6])
@test eltype(e) == Rational{Int}
end