Skip to content
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

V0p3p11b #133

Merged
merged 3 commits into from
Aug 28, 2024
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
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
Loading