Skip to content

Commit

Permalink
spacing -> rasterpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Dec 8, 2023
1 parent 4d4f41a commit 38b220a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridVisualize"
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
authors = ["Juergen Fuhrmann <[email protected]>"]
version = "1.4.1"
version = "1.5.0-DEV"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
16 changes: 4 additions & 12 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ end
"""
vectorsample(grid::ExtendableGrid{Tv, Ti}, v;
offset = :default,
spacing = :default,
rasterpoints = 15,
reltol = 1.0e-10,
gridscale = 1.0,
xlimits = (1, -1),
Expand All @@ -161,7 +161,7 @@ The code is 3D ready.
"""
function vectorsample(grid::ExtendableGrid{Tv, Ti}, v;
offset = :default,
spacing = :default,
rasterpoints = 32,
reltol = 1.0e-10,
gridscale = 1.0,
xlimits = (1, -1),
Expand Down Expand Up @@ -215,22 +215,14 @@ function vectorsample(grid::ExtendableGrid{Tv, Ti}, v;
tol = reltol * extent

# point spacing
if spacing == :default
spacing = [extent / 15 for i = 1:dim]
elseif isa(spacing, Number)
spacing = [spacing for i = 1:dim] * gridscale
else
# else assume spacing vector has been given
spacing = spacing * gridscale
end
spacing = [extent / rasterpoints for i = 1:dim]

# index range
ijkmax = ones(Int, 3)
for idim = 1:dim
ijkmax[idim] = ceil(Int64, (cminmax[idim][2] - offset[idim]) / spacing[idim]) + 1
end
@show ijkmax
@show spacing

# The ijk raster corresponds to a tensorproduct grid
# spanned by x,y and z coordinate vectors. Here, we build them
# in order to avoid to calculate them from the raster indices
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ function default_plot_kwargs()
:levelalpha => Pair(0.25, "3D isolevel alpha"),
:planealpha => Pair(0.25, "3D plane section alpha"),
:tetxplane_tol => Pair(0.0, "tolerance for tet-plane intersection in 3D"),
:spacing => Pair(:default,
"Spacing of quiver/streamplot interpolation points in vector plot"),
:rasterpoints => Pair(16,
"Number of quiver points resp. half number of streamplot interpolation points in the maximum extent direction. "),
:offset => Pair(:default, "Offset of quiver grid"),
:vscale => Pair(1.0, "Vector field scale for quiver grid"),
:vconstant => Pair(false, "Set all arrow length constant in vector plot"),
Expand All @@ -335,7 +335,7 @@ function default_plot_kwargs()
:yplanes => Pair([prevfloat(Inf)], "3D y plane positions or number thereof"),
:zplanes => Pair([prevfloat(Inf)], "3D z plane positions or number thereof"),
:zoom => Pair(1.0, "Zoom level"),
:gridscale => Pair(1, "Grid scale factor. Will be applied also to planes, spacing."),
:gridscale => Pair(1, "Grid scale factor. Will be applied also to planes, spacing"),
:azim => Pair(-60, "3D azimuth angle (in degrees)"),
:elev => Pair(30, "3D elevation angle (in degrees)"),
:perspectiveness => Pair(0.25,
Expand Down
9 changes: 5 additions & 4 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ end
function vectorplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
XMakie = ctx[:Plotter]

rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], spacing = ctx[:spacing], offset = ctx[:offset])
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], rasterpoints = ctx[:rasterpoints], offset = ctx[:offset])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize], vconstant = ctx[:vconstant])

set_plot_data!(ctx, :arrowdata, (qc = qc, qv = qv))
Expand Down Expand Up @@ -777,7 +777,7 @@ end
function streamplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
XMakie = ctx[:Plotter]

rc, rv = vectorsample(grid, func; spacing = ctx[:spacing], offset = ctx[:offset], xlimits = ctx[:xlimits],
rc, rv = vectorsample(grid, func; rasterpoints = 2 * ctx[:rasterpoints], offset = ctx[:offset], xlimits = ctx[:xlimits],
ylimits = ctx[:ylimits], gridscale = ctx[:gridscale])

x = rc[1]
Expand All @@ -789,9 +789,10 @@ function streamplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)

xextent = x[end] - x[begin]
yextent = y[end] - y[begin]

maxextent = max(xextent, yextent)
gridstep = maxextent / 32
gridsize = (Int(ceil(xextent / gridstep)), Int(ceil(yextent / gridstep)), 20)
gridstep = maxextent / (2 * ctx[:rasterpoints])
gridsize = (Int(ceil(xextent / gridstep)), Int(ceil(yextent / gridstep)), 2 * ctx[:rasterpoints])

set_plot_data!(ctx, :streamdata, (xinterval = x[begin] .. x[end], yinterval = y[begin] .. y[end], f = f))

Expand Down
2 changes: 1 addition & 1 deletion src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function vectorplot!(ctx, TP::Type{PlotsType}, ::Type{Val{2}}, grid, func)
ctx[:ax] = Plots.plot(; title = ctx[:title])
end
p = ctx[:ax]
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], spacing = ctx[:spacing], offset = ctx[:offset])
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], rasterpoints = ctx[:rasterpoints], offset = ctx[:offset])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize])

Plots.quiver!(p, qc[1, :], qc[2, :]; quiver = (qv[1, :], qv[2, :]), color = :black)
Expand Down
4 changes: 2 additions & 2 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ function vectorplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid, func)
ax.set_aspect(ctx[:aspect])
ax.set_title(ctx[:title])

rc, rv = vectorsample(grid, func; spacing = ctx[:spacing], offset = ctx[:offset], xlimits = ctx[:xlimits],
rc, rv = vectorsample(grid, func; rasterpoints = ctx[:rasterpoints], offset = ctx[:offset], xlimits = ctx[:xlimits],
ylimits = ctx[:ylimits], gridscale = ctx[:gridscale])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize], vconstant = ctx[:vconstant])

Expand Down Expand Up @@ -720,7 +720,7 @@ function streamplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid, func)
xout, yout
end

rc, rv = vectorsample(grid, func; spacing = ctx[:spacing], offset = ctx[:offset], xlimits = ctx[:xlimits],
rc, rv = vectorsample(grid, func; rasterpoints = 2 * ctx[:rasterpoints], offset = ctx[:offset], xlimits = ctx[:xlimits],
ylimits = ctx[:ylimits], gridscale = ctx[:gridscale])

X, Y = meshgrid(rc)
Expand Down

0 comments on commit 38b220a

Please sign in to comment.