diff --git a/Project.toml b/Project.toml index 1527d7d..90c54c1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MeshArrays" uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683" authors = ["gaelforget "] -version = "0.3.10" +version = "0.3.11" [deps] CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31" diff --git a/src/Type_gcmarray.jl b/src/Type_gcmarray.jl index f8d56c1..857fcb0 100644 --- a/src/Type_gcmarray.jl +++ b/src/Type_gcmarray.jl @@ -243,7 +243,7 @@ function Base.similar(A::gcmarray;m::varmeta=defaultmeta) if ndims(A)==1 B=gcmarray(similar(A.grid),eltype(A),copy(A.fSize),copy(A.fIndex); meta=m) else - B=gcmarray(similar(A.grid),eltype(A),copy(A.fSize),copy(A.fIndex),size(A,2); meta=m) + B=gcmarray(similar(A.grid),eltype(A),copy(A.fSize),copy(A.fIndex),size(A)[2:end]...; meta=m) end return B end @@ -259,7 +259,7 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{gcmarray}}, if ndims(A)==1 B=gcmarray(similar(A.grid),ElType,copy(A.fSize),copy(A.fIndex)) else - B=gcmarray(similar(A.grid),ElType,copy(A.fSize),copy(A.fIndex),size(A,2)) + B=gcmarray(similar(A.grid),ElType,copy(A.fSize),copy(A.fIndex),size(A)[2:end]...) end return B end diff --git a/src/Types.jl b/src/Types.jl index ce9e79b..44c91b8 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -131,6 +131,8 @@ function fill(val::Any,a::AbstractMeshArray) return c end +fill(val::Any,a::gcmgrid,args...) = val .* ones(a,args...) + function fill!(a::AbstractMeshArray,val::Any) for I in eachindex(a.f) fill!(a.f[I],val) @@ -171,3 +173,39 @@ function *(a::AbstractMeshArray,b::AbstractMeshArray) end return c end + +function *(a::AbstractMeshArray,b::Array) + c=MeshArray(a.grid,eltype(a[eachindex(a.f)[1]]),size(b)...) + for f in 1:length(a.f) + for bb in eachindex(IndexCartesian(),b) + c.f[f,bb.I...].=b[bb.I...]*a[f] + end + end + return c +end + +import Base: ones, zeros + +function zeros(a::gcmgrid,args...) + b=MeshArray(a) + [b.f[c].=1.0 for c in eachindex(b.f)] + (length(args)>0 ? b*ones(args...) : b) +end + +function ones(a::gcmgrid,args...) + b=MeshArray(a) + [b.f[c].=1.0 for c in eachindex(b.f)] + (length(args)>0 ? b*ones(args...) : b) +end + +function zeros(a::AbstractMeshArray) + b=similar(a) + [b.f[c].=0.0 for c in eachindex(b.f)] + b +end + +function ones(a::AbstractMeshArray) + b=similar(a) + [b.f[c].=1.0 for c in eachindex(b.f)] + b +end