Skip to content

Commit

Permalink
add default Multivalue component_name
Browse files Browse the repository at this point in the history
Moved components naming into MultiValue's API and set a default
  • Loading branch information
Antoinemarteau committed Oct 15, 2024
1 parent 60b9bcc commit 5e6d8d6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 60 deletions.
12 changes: 12 additions & 0 deletions src/TensorValues/MultiValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ end
function data_index(::Type{<:MultiValue},i...)
@abstractmethod
end

"""
indep_components_names(::MultiValue)
Returns an array of strings containing the component labels in the order they are stored internally, consistently with _prepare_data(::Multivalue)
If all dimensions of the tensor shape S are smaller than 3, the components should be named with letters "X","Y" and "Z" similarly to the automatic naming of Paraview. Else, if max(S)>3, they are labeled from "1" to "\$dim".
"""
function indep_components_names(::MultiValue{S,T,N,L}) where {S,T,N,L}
return ["$i" for i in 1:L]
end

13 changes: 13 additions & 0 deletions src/TensorValues/SymFourthOrderTensorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,16 @@ length(::SymFourthOrderTensorValue{D}) where {D} = length(SymFourthOrderTensorVa
num_components(::Type{<:SymFourthOrderTensorValue{D}}) where {D} = length(SymFourthOrderTensorValue{D})
num_components(::SymFourthOrderTensorValue{D}) where {D} = num_components(SymFourthOrderTensorValue{D})

###############################################################
# VTK export (SymFourthOrderTensorValue)
###############################################################

function indep_components_names(::Type{<:SymFourthOrderTensorValue{A}}) where A
if A>3
return ["$i$j$k$l" for i in 1:A for j in i:A for k in 1:A for l in k:A ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j]*c_name[k]*c_name[l] for i in 1:A for j in i:A for k in 1:A for l in k:A ]
end
end

13 changes: 13 additions & 0 deletions src/TensorValues/SymTensorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ length(::SymTensorValue{D}) where {D} = length(SymTensorValue{D})

num_components(::Type{<:SymTensorValue{D}}) where {D} = length(SymTensorValue{D})
num_components(::SymTensorValue{D}) where {D} = num_components(SymTensorValue{D})

###############################################################
# VTK export (SymTensorValue)
###############################################################

function indep_components_names(::Type{<:SymTensorValue{D}}) where D
if D>3
return ["$i$j" for i in 1:D for j in i:D ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j] for i in 1:D for j in i:D ]
end
end
14 changes: 13 additions & 1 deletion src/TensorValues/TensorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct TensorValue{D1,D2,T,L} <: MultiValue{Tuple{D1,D2},T,2,L}
end

###############################################################
# Constructors
# Constructors
###############################################################

# Empty TensorValue constructor
Expand Down Expand Up @@ -145,3 +145,15 @@ num_components(::Type{<:TensorValue{D}}) where {D} = length(TensorValue{D,D})
num_components(::Type{<:TensorValue{D1,D2}}) where {D1,D2} = length(TensorValue{D1,D2})
num_components(::TensorValue{D1,D2}) where {D1,D2} = num_components(TensorValue{D1,D2})

###############################################################
# VTK export (TensorValue)
###############################################################

function indep_components_names(::Type{<:TensorValue{D1,D2}}) where {D1,D2}
if D1>3 || D2>3
return ["$i$j" for i in 1:D1 for j in 1:D2 ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j] for i in 1:D1 for j in 1:D2 ]
end
end
1 change: 1 addition & 0 deletions src/TensorValues/TensorValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export ⋅¹
export ²
export double_contraction
export data_index
export indep_components_names

import Base: show
import Base: zero, one
Expand Down
13 changes: 13 additions & 0 deletions src/TensorValues/ThirdOrderTensorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ length(::ThirdOrderTensorValue{D1,D2,D3}) where {D1,D2,D3} = length(ThirdOrderTe
num_components(::Type{<:ThirdOrderTensorValue{D1,D2,D3}}) where {D1,D2,D3} = length(ThirdOrderTensorValue{D1,D2,D3})
num_components(::ThirdOrderTensorValue{D1,D2,D3}) where {D1,D2,D3} = num_components(ThirdOrderTensorValue{D1,D2,D3})

###############################################################
# VTK export (ThirdOrderTensorValue)
###############################################################

function indep_components_names(::Type{<:ThirdOrderTensorValue{D1,D2,D3}}) where {D1,D2,D3}
if D1>3 || D2>3 || D3>3
return ["$i$j$k" for i in 1:D1 for j in 1:D2 for k in 1:D3 ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j]*c_name[k] for i in 1:D1 for j in 1:D2 for k in 1:D3]
end
end

14 changes: 14 additions & 0 deletions src/TensorValues/VectorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ length(::VectorValue{D}) where {D} = length(VectorValue{D})

num_components(::Type{<:VectorValue{D}}) where {D} = length(VectorValue{D})
num_components(::VectorValue{D}) where {D} = num_components(VectorValue{D})

###############################################################
# VTK export (VectorValue)
###############################################################

function indep_components_names(::Type{<:VectorValue{A}}) where A
[ "$i" for i in 1:A ]
if A>3
return ["$i" for i in 1:A ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i] for i in 1:A ]
end
end
60 changes: 1 addition & 59 deletions src/Visualization/Vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,65 +188,7 @@ end

_data_component_names(v) = nothing

_data_component_names(v::AbstractArray{T}) where T<:MultiValue = _data_component_names(T)

"""
Return an array containing the component labels in the order they are stored internally, consistently with _prepare_data(::Multivalue)
For spacial dimensions d=1,2 or 3, the components are named with letters X,Y and Z similarly to the automatic naming of Paraview. Else, if d>3, they are numbered from 1 to d.
"""
_data_component_names(::Type{<:MultiValue}) = @notimplemented

function _data_component_names(::Type{<:VectorValue{A}}) where A
[ "$i" for i in 1:A ]
if A>3
return ["$i" for i in 1:A ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i] for i in 1:A ]
end
end

function _data_component_names(::Type{<:TensorValue{A,B}}) where {A,B}
if A>3 || B>3
return ["$i$j" for i in 1:A for j in 1:B ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j] for i in 1:A for j in 1:B ]
end
end

_data_component_names(::Type{<:SymTensorValue{1}})= ["XX"]
_data_component_names(::Type{<:SymTensorValue{2}})= ["XX","XY","YY"]
_data_component_names(::Type{<:SymTensorValue{3}})= [
"XX", "XY", "XZ", "YY", "YZ", "ZZ"
]
function _data_component_names(::Type{<:SymTensorValue{A}}) where A
if A>3
return ["$i$j" for i in 1:A for j in i:A ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j] for i in 1:A for j in i:A ]
end
end

function _data_component_names(::Type{<:ThirdOrderTensorValue{A,B,C}}) where {A,B,C}
if A>3 || B>3 || C>3
return ["$i$j$k" for i in 1:A for j in 1:B for k in 1:C ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j]*c_name[k] for i in 1:A for j in 1:B for k in 1:C]
end
end

function _data_component_names(::Type{<:SymFourthOrderTensorValue{A}}) where A
if A>3
return ["$i$j$k$l" for i in 1:A for j in i:A for k in 1:A for l in k:A ]
else
c_name = ["X", "Y", "Z"]
return [c_name[i]*c_name[j]*c_name[k]*c_name[l] for i in 1:A for j in i:A for k in 1:A for l in k:A ]
end
end
_data_component_names(v::AbstractArray{T}) where T<:MultiValue = indep_components_names(T)

_prepare_data(v) = v

Expand Down

0 comments on commit 5e6d8d6

Please sign in to comment.