Skip to content

Commit

Permalink
return streamfunc and potential from field_on_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
archermarx committed Dec 21, 2023
1 parent 20f5e8e commit 913c242
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0-rc3"
manifest_format = "2.0"
project_hash = "1acd6ddf9d06c1be1ead153f3ed5ae7b14060395"
project_hash = "dd0d912228d3570dd0b442fd72dbc8a9b466421d"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down Expand Up @@ -47,11 +47,11 @@ version = "1.6.0"

[[deps.Elliptic2]]
deps = ["DelimitedFiles", "SpecialFunctions"]
git-tree-sha1 = "6a65379fcb32951cff6f98602884b9364aa6e556"
git-tree-sha1 = "fc0b6310c912f838661e19e739667d979683569c"
repo-rev = "master"
repo-url = "https://github.com/archermarx/Elliptic2.jl"
uuid = "0b55928f-c416-41db-a823-c7dfe4e8fda4"
version = "0.1.0"
version = "0.2.0"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LoopFieldCalc"
uuid = "896acac2-5fe1-47fe-8ead-27e3a9bc5c85"
authors = ["Thomas Marks <[email protected]> and contributors"]
version = "0.3.0"
version = "0.3.1"

[deps]
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
Expand All @@ -10,7 +10,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
julia = "1"
Elliptic2 = ">=0.2"
Elliptic2 = ">=0.1"
Contour = "0.6.2"
Printf = "<0.0.1, 1"

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ zs = -2.0:0.01:2.0
# Define current loops. Here, we only have the single loop, defined above
loops = [loop]

# Compute the magnetic field components
Bx, By, Bz = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)
# Compute the magnetic field components, along with magnetic stream function and scalar potential
Bx, By, Bz, streamfunc, potential = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)
```

You can write output of this function to a Tecplot-compatible ASCII data format
Expand Down Expand Up @@ -136,7 +136,7 @@ outer_coil = [

# Combine inner and outer coil loops into a single vector and compute field
loops = [outer_coil; inner_coil]
Bx, By, Bz = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)
Bx, By, Bz, streamfunc, potential = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)

# Write output. By reversing z and y and transposing the magnetic field matrices, we
# can rotate the output so that the loop axis is aligned with the x axis
Expand Down
2 changes: 1 addition & 1 deletion examples/example_1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ zs = -2.0:0.01:2.0
loops = [loop]

# Compute the magnetic field components
Bx, By, Bz = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)
Bx, By, Bz, _, _ = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)

LoopFieldCalc.write_field("examples/example_1.dat", ys, zs, By[1, :, :], Bz[1, :, :])
2 changes: 1 addition & 1 deletion examples/example_2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ outer_coil = [

# Combine inner and outer coil loops into a single vector and compute field
loops = [outer_coil; inner_coil]
Bx, By, Bz = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)
Bx, By, Bz, _, _ = LoopFieldCalc.field_on_grid(loops, xs, ys, zs)

# Write output. By reversing z and y and transposing the magnetic field matrices, we
# can rotate the output so that the loop axis is aligned with the x axis
Expand Down
8 changes: 6 additions & 2 deletions src/LoopFieldCalc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ function field_on_grid(loops, xs, ys, zs)
Bx = zeros(Nx, Ny, Nz)
By = zeros(Nx, Ny, Nz)
Bz = zeros(Nx, Ny, Nz)
streamfunc = zeros(Nx, Ny, Nz)
potential = zeros(Nx, Ny, Nz)

for (i, x) in enumerate(xs), (j, y) in enumerate(ys), (k, z) in enumerate(zs)
for loop in loops
bx, by, bz, _, _ = field_at_point(loop, CartesianPoint(x, y, z))
bx, by, bz, s, p = field_at_point(loop, CartesianPoint(x, y, z))
Bx[i, j, k] += bx
By[i, j, k] += by
Bz[i, j, k] += bz
streamfunc[i, j, k] += s
potential[i, j, k] += p
end
end

return Bx, By, Bz
return Bx, By, Bz, streamfunc, potential
end

"""
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using LoopFieldCalc: CurrentLoop, CartesianPoint, CylindricalPoint, field_on_gri
Bz_indiv = zeros(size(Bz))

for loop in loops
Bx_i, By_i, Bz_i = field_on_grid([loop], xs, ys, zs)
Bx_i, By_i, Bz_i, _, _ = field_on_grid([loop], xs, ys, zs)
@. Bx_indiv += Bx_i
@. By_indiv += By_i
@. Bz_indiv += Bz_i
Expand Down

0 comments on commit 913c242

Please sign in to comment.