From 38b220a09d842d0f9c3f847170774ed9f2219be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Fri, 8 Dec 2023 16:01:43 +0100 Subject: [PATCH] spacing -> rasterpoints --- Project.toml | 2 +- src/common.jl | 16 ++++------------ src/dispatch.jl | 6 +++--- src/makie.jl | 9 +++++---- src/plots.jl | 2 +- src/pyplot.jl | 4 ++-- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Project.toml b/Project.toml index 6e750b1..68b684f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GridVisualize" uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8" authors = ["Juergen Fuhrmann "] -version = "1.4.1" +version = "1.5.0-DEV" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" diff --git a/src/common.jl b/src/common.jl index c1eefd2..95226a0 100644 --- a/src/common.jl +++ b/src/common.jl @@ -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), @@ -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), @@ -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 diff --git a/src/dispatch.jl b/src/dispatch.jl index 54e7004..243e6ff 100644 --- a/src/dispatch.jl +++ b/src/dispatch.jl @@ -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"), @@ -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, diff --git a/src/makie.jl b/src/makie.jl index 7160eb5..8a57bb7 100644 --- a/src/makie.jl +++ b/src/makie.jl @@ -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)) @@ -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] @@ -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)) diff --git a/src/plots.jl b/src/plots.jl index 5ef0ecf..9f5141a 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -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) diff --git a/src/pyplot.jl b/src/pyplot.jl index 9b19bf9..b1dd2f4 100644 --- a/src/pyplot.jl +++ b/src/pyplot.jl @@ -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]) @@ -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)