Set array dimensions in composite type

I don’t know of any better way than parameterizing Compound with three independent parameters (e.g. N, N1, N2) and enforce the relation between them in an inner constructor.

Something along the lines of:

julia> struct Compound{N, N1, N2}
           scalar_field :: Array{Float64,N}  # N is the number of spatial dimensions of the field
           vector_field :: Array{Float64,N1} # N1 should be N+1
           tensor_field :: Array{Float64,N2} # N2 should be N+2
       
           function Compound(N)
               new{N, N+1, N+2}()
           end
       end

julia> Compound(5)
Compound{5,6,7}(#undef, #undef, #undef)
1 Like