Skip to content

Commit

Permalink
Add a method for rk4 3D CartesianGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Oct 30, 2023
1 parent d41018b commit 0ce4b8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/structured3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,25 @@ function trace3d_euler(fieldx::F, fieldy::F, fieldz::F, startx::T, starty::T, st

trace3d_euler(fieldx, fieldy, fieldz, startx, starty, startz, gridx, gridy, gridz;
kwargs...)
end

"""
trace3d_rk4(fieldx, fieldy, fieldz, startx, starty, startz, grid::CartesianGrid;
maxstep=20000, ds=0.01, gridtype="ndgrid", direction="both")
See also [`trace3d_euler`](@ref).
"""
function trace3d_rk4(fieldx::F, fieldy::F, fieldz::F, startx::T, starty::T, startz::T,
grid::CartesianGrid; kwargs...) where {F, T}

gridmin = coordinates(minimum(grid))
gridmax = coordinates(maximum(grid))
Δx = spacing(grid)

gridx = range(gridmin[1], gridmax[1], step=Δx[1])
gridy = range(gridmin[2], gridmax[2], step=Δx[2])
gridz = range(gridmin[3], gridmax[3], step=Δx[3])

trace3d_rk4(fieldx, fieldy, fieldz, startx, starty, startz, gridx, gridy, gridz;
kwargs...)
end
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ using Test
alg=Euler(), ds=0.2, maxstep=200)

@test length(x1) == 170 && x1[end] y1[end] z1[end]

# RK4 by default
x1, y1, z1 = trace(bx, bz, bz, xs, ys, zs, x, y, z;
ds=0.2, maxstep=200, direction="forward")

@test length(x1) == 152 && x1[end] y1[end] z1[end]
end

@testset "2D unstructured mesh" begin
Expand Down

0 comments on commit 0ce4b8a

Please sign in to comment.