Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
svretina committed Jan 8, 2024
1 parent a13ea1d commit ce921d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
7 changes: 1 addition & 6 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.9.3"
manifest_format = "2.0"
project_hash = "f964ff8ef40f61a06c7ee69d553f9d6720b1923f"
project_hash = "451b73d4767ecea7f5c88392cffbddac7b4059fe"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand All @@ -12,11 +12,6 @@ deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.5+0"

[[deps.IterTools]]
git-tree-sha1 = "4ced6667f9974fc5c5943fa5e2ef1ca43ea9e450"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.8.0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

Expand Down
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Stamatis Vretinaris"]
version = "1.0.0-DEV"

[deps]
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
10 changes: 5 additions & 5 deletions src/Functions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Functions

import ..Grids
import IterTools: product
import Base.Iterators

export GridFunction, coords

Expand All @@ -24,14 +24,14 @@ function Grids.coords(f::GridFunction)
return Grids.coords(f.grid)
end

function GridFunction(x::Grids.UniformGrid{T}, f::Function) where {T<:Real}
npoints = Tuple(x.ncells) .+ 1
function GridFunction(g::Grids.UniformGrid{T}, f::Function) where {T<:Real}
npoints = Tuple(g.ncells) .+ 1
values = Array{Float64}(undef, npoints)
grid_coords = collect(product((Grids.coords(x))...))
grid_coords = collect(Base.Iterators.product((Grids.coords(g))...))
for indices in CartesianIndices(npoints)
values[indices] = f([grid_coords[indices]...])
end
return GridFunction(x, values)
return GridFunction(g, values)
end


Expand Down
12 changes: 9 additions & 3 deletions test/FunctionTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ end
end

@testset "Analytic Function provided" begin
g = UniformGrid(d, n)
f = GridFunction(g, sin)
@test f.values == sin(g)
g = UniformGrid(d, n, 3)
f = GridFunction(g, x -> sin(x[1]) * cos(x[2]) * sin(x[3]))
x = coords(g)
vals = similar(f.values)
for indx in CartesianIndices(x)
i, j, k = indx
vals[i, j, k] = sin(x[i, j, k]) * cos(x[i, j, k]) * sin(x[i, j, k])
end
@test f.values == vals
end

@testset "1d grid special case" begin
Expand Down

0 comments on commit ce921d2

Please sign in to comment.