From b03ecda6e35d04897a89dd12a8c84a1b2f84fcf9 Mon Sep 17 00:00:00 2001 From: Hongyang Zhou Date: Mon, 11 Nov 2024 18:57:14 -1000 Subject: [PATCH] Interp2d (#68) * Refactor interp2d * Add interp2d benchmark * Bump patch --- Project.toml | 2 +- benchmark/benchmarks.jl | 6 ++++-- src/Batsrus.jl | 2 +- src/utility.jl | 5 ++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 1e383171..2658e87d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Batsrus" uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753" authors = ["Hongyang Zhou "] -version = "0.7.0" +version = "0.7.1" [deps] FortranFiles = "c58ffaec-ab22-586d-bfc5-781a99fd0b10" diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index ffc17e32..def1c9d7 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -19,9 +19,11 @@ SUITE["read"]["ASCII"] = @benchmarkable load($file) file = joinpath(directory, files[2]) bd = load(file) +SUITE["read"]["Binary structured"] = @benchmarkable load($file) SUITE["read"]["Extract density"] = @benchmarkable Batsrus.getvar($bd, "Rho") SUITE["read"]["Extract B"] = @benchmarkable Batsrus.getvar($bd, "B") -SUITE["read"]["Binary structured"] = @benchmarkable load($file) - +SUITE["read"]["Interp2d"] = @benchmarkable Batsrus.interp2d($bd, "rho") + file = joinpath(directory, files[3]) +bd = load(file) SUITE["read"]["Anisotropy"] = @benchmarkable bd["Anisotropy1"] diff --git a/src/Batsrus.jl b/src/Batsrus.jl index bc704ebc..731b8e3b 100644 --- a/src/Batsrus.jl +++ b/src/Batsrus.jl @@ -3,7 +3,7 @@ module Batsrus # # Hongyang Zhou, hyzhou@umich.edu -using LinearAlgebra: normalize, ×, ⋅ +using LinearAlgebra: normalize, ×, ⋅, Adjoint using Printf, Reexport, Requires using Parsers using Interpolations: cubic_spline_interpolation, BSpline, Linear, scale, interpolate diff --git a/src/utility.jl b/src/utility.jl index 1419d09d..51c098b7 100644 --- a/src/utility.jl +++ b/src/utility.jl @@ -13,10 +13,13 @@ data resolution is the same as the original. - `useMatplotlib=true`: Whether to Matplotlib (somehow faster) or NaturalNeighbours for scattered interpolation. """ function interp2d(bd::BATS{2, 3, T}, var::AbstractString, - plotrange::Vector=[-Inf, Inf, -Inf, Inf], plotinterval::Real=Inf; + plotrangeIn::Vector=[-Inf32, Inf32, -Inf32, Inf32], plotinterval::Real=Inf32; innermask::Bool=false, rbody::Real=1.0, useMatplotlib::Bool=true) where T x, w = bd.x, bd.w varIndex_ = findindex(bd, var) + plotrange = T.(plotrangeIn) + + local Wi::Union{Matrix{T}, Adjoint{T, Matrix{T}}} if bd.head.gencoord # Generalized coordinates X, Y = eachslice(x, dims=3)