Skip to content

Commit

Permalink
Merge pull request #133 from gaelforget/v0p3p11b
Browse files Browse the repository at this point in the history
V0p3p11b
  • Loading branch information
gaelforget committed Aug 28, 2024
2 parents cec6e3b + 3dba89d commit 7fb309f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshArrays"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
authors = ["gaelforget <gforget@mit.edu>"]
version = "0.3.10"
version = "0.3.11"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down
4 changes: 2 additions & 2 deletions src/Type_gcmarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 7fb309f

Please sign in to comment.