Skip to content

Commit

Permalink
Merge pull request #39 from ProjectTorreyPines/OMAS_IMAS
Browse files Browse the repository at this point in the history
Replace OMAS with IMASDD in GGDUtils
  • Loading branch information
anchal-physics authored Mar 20, 2024
2 parents e46cfdc + b8df68c commit 238d675
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 115 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.2.1"
[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
IMASDD = "06b86afa-9f21-11ec-2ef8-e51b8960cfc5"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
OMAS = "91cfaa06-6526-4804-8666-b540b3feef2f"
Expand Down
10 changes: 5 additions & 5 deletions examples/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"git@github.com:ProjectTorreyPines/OMAS.jl.git\")\n",
"Pkg.add(url=\"git@github.com:ProjectTorreyPines/IMASDD.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")\n",
"Pkg.add(\"LaTeXStrings\")"
Expand All @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"using OMAS\n",
"using IMASDD\n",
"using GGDUtils\n",
"using Plots\n",
"using LaTeXStrings"
Expand All @@ -48,7 +48,7 @@
"metadata": {},
"outputs": [],
"source": [
"dd = OMAS.json2imas(\"../samples/time_dep_edge_profiles_last_step_only.json\")\n",
"dd = IMASDD.json2imas(\"../samples/time_dep_edge_profiles_last_step_only.json\")\n",
"grid_ggd = dd.edge_profiles.grid_ggd[1]\n",
"space = grid_ggd.space[1]"
]
Expand Down Expand Up @@ -146,15 +146,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"display_name": "Julia 1.9.4",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
"version": "1.9.4"
},
"orig_nbformat": 4
},
Expand Down
10 changes: 5 additions & 5 deletions examples/plotting_interferometer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"git@github.com:ProjectTorreyPines/OMAS.jl.git\")\n",
"Pkg.add(url=\"git@github.com:ProjectTorreyPines/IMASDD.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")"
]
Expand All @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"using OMAS\n",
"using IMASDD\n",
"using GGDUtils\n",
"using Plots"
]
Expand All @@ -53,7 +53,7 @@
"metadata": {},
"outputs": [],
"source": [
"ids = OMAS.json2imas(\"$(@__DIR__)/../samples/time_dep_edge_profiles_with_interferometer.json\")\n",
"ids = IMASDD.json2imas(\"$(@__DIR__)/../samples/time_dep_edge_profiles_with_interferometer.json\")\n",
"grid_ggd = ids.edge_profiles.grid_ggd[1]\n",
"space = grid_ggd.space[1]"
]
Expand Down Expand Up @@ -226,15 +226,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"display_name": "Julia 1.9.4",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
"version": "1.9.4"
},
"orig_nbformat": 4
},
Expand Down
9 changes: 5 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ env_with_cloned_repo r:
@echo "Creating Julia environment by creating local clones of dependent repositories"
@echo "Cloning the repositories and generating Manifest.toml"
-dn=$(shell dirname $(shell pwd)); \
if [[ "$${dn:(-10)}" == ".julia/dev" ]]; then rn="OMAS" ; else rn="OMAS.jl"; fi; \
git clone "git@github.com:ProjectTorreyPines/OMAS.jl.git" ../$${rn}; \
julia --project=. -e 'using Pkg; Pkg.rm("OMAS"); Pkg.develop(path="../'$${rn}'"); Pkg.instantiate()'
if [[ "$${dn:(-10)}" == ".julia/dev" ]]; then ext="" ; else ext=".jl";fi; \
git clone "git@github.com:ProjectTorreyPines/OMAS.jl.git" ../OMAS$${ext}; \
git clone "git@github.com:ProjectTorreyPines/IMASDD.jl.git" ../IMASDD$${ext}; \
julia --project=. -e 'using Pkg; Pkg.rm(["OMAS", "IMASDD"]); Pkg.develop(path="../OMAS'$${ext}'"); Pkg.develop(path="../IMASDD'$${ext}'"); Pkg.instantiate()'

env_with_git_url u:
@echo "Pulling sample files using dvc"
-dvc pull
@echo "Creating Julia environment with the git urls without creating local clones"
@echo "Generating Project.toml and Manifest.toml"
julia --project=. -e 'using Pkg; Pkg.rm("OMAS"); Pkg.add(url="git@github.com:ProjectTorreyPines/OMAS.jl.git", rev="master"); Pkg.instantiate()'
julia --project=. -e 'using Pkg; Pkg.rm(["OMAS", "IMASDD"]); Pkg.add(url="git@github.com:ProjectTorreyPines/OMAS.jl.git", rev="master"); Pkg.add(url="git@github.com:ProjectTorreyPines/IMASDD.jl.git", rev="master"); Pkg.instantiate()'

clean:
@echo "Deleting Manifest.toml"
Expand Down
2 changes: 1 addition & 1 deletion src/GGDUtils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GGDUtils

using OMAS: OMAS
import OMAS as IMASDD

const inv_16pi = 1.0 / (16π)

Expand Down
74 changes: 37 additions & 37 deletions src/interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interp
export get_kdtree
export get_TPS_mats

function get_kdtree(space::OMAS.edge_profiles__grid_ggd___space)
function get_kdtree(space::IMASDD.edge_profiles__grid_ggd___space)
grid_nodes = space.objects_per_dimension[1].object
grid_faces = space.objects_per_dimension[3].object
grid_faces = [cell for cell grid_faces if length(cell.nodes) == 4]
Expand All @@ -19,8 +19,8 @@ function get_kdtree(space::OMAS.edge_profiles__grid_ggd___space)
end

function get_kdtree(
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset,
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset,
)
subset_centers = get_subset_centers(space, subset)
return KDTree([SVector{2}(sc) for sc subset_centers]; leafsize=10)
Expand Down Expand Up @@ -167,15 +167,15 @@ function interp(y::Vector{T}, x::Vector{Tuple{U, U}}) where {T <: Real, U <: Rea
return interp(y, get_TPS_mats(x))
end

function get_TPS_mats(space::OMAS.edge_profiles__grid_ggd___space)
function get_TPS_mats(space::IMASDD.edge_profiles__grid_ggd___space)
nodes = [Tuple(node.geometry) for node space.objects_per_dimension[1].object]
return get_TPS_mats(nodes)
end

"""
interp(
prop_values::Vector{T},
space::OMAS.edge_profiles__grid_ggd___space
space::IMASDD.edge_profiles__grid_ggd___space
) where {T <: Real}
Expand All @@ -185,23 +185,23 @@ of the space.
"""
function interp(
prop_values::Vector{T},
space::OMAS.edge_profiles__grid_ggd___space,
space::IMASDD.edge_profiles__grid_ggd___space,
) where {T <: Real}
return interp(prop_values, get_TPS_mats(space))
end

function get_TPS_mats(
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset,
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset,
)
return get_TPS_mats(get_subset_centers(space, subset))
end

"""
interp(
prop_values::Vector{Real},
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset
)
Expand All @@ -210,16 +210,16 @@ it is assumed that the property values are provided for each element of the subs
"""
function interp(
prop_values::Vector{T},
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset,
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset,
) where {T <: Real}
return interp(prop_values, get_TPS_mats(space, subset))
end

"""
interp(
prop::edge_profiles__prop_on_subset,
grid_ggd::OMAS.edge_profiles__grid_ggd,
grid_ggd::IMASDD.edge_profiles__grid_ggd,
value_field::Symbol=:values
)
Expand All @@ -231,7 +231,7 @@ get_e_field_par = interp(dd.edge_profiles.ggd[1].e_field[1], grid_ggd, :parallel
"""
function interp(
prop::edge_profiles__prop_on_subset,
grid_ggd::OMAS.edge_profiles__grid_ggd,
grid_ggd::IMASDD.edge_profiles__grid_ggd,
value_field::Symbol=:values,
)
subset = get_grid_subset_with_index(grid_ggd, prop.grid_subset_index)
Expand All @@ -241,9 +241,9 @@ end

"""
interp(
prop_arr::Vector{T},
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset,
prop_arr::AbstractVector{T},
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset,
value_field::Symbol=:values
) where {T <: edge_profiles__prop_on_subset}
Expand All @@ -253,9 +253,9 @@ sol = get_grid_subset_with_index(dd.edge_profiles.grid_ggd[1], 23)
get_electron_density = interp(dd.edge_profiles.ggd[1].electrons.density, space, sol)
"""
function interp(
prop_arr::Vector{T},
space::OMAS.edge_profiles__grid_ggd___space,
subset::OMAS.edge_profiles__grid_ggd___grid_subset,
prop_arr::AbstractVector{T},
space::IMASDD.edge_profiles__grid_ggd___space,
subset::IMASDD.edge_profiles__grid_ggd___grid_subset,
value_field::Symbol=:values,
) where {T <: edge_profiles__prop_on_subset}
prop = get_prop_with_grid_subset_index(prop_arr, subset.identifier.index)
Expand All @@ -264,8 +264,8 @@ end

"""
interp(
prop_arr::Vector{T},
grid_ggd::OMAS.edge_profiles__grid_ggd,
prop_arr::AbstractVector{T},
grid_ggd::IMASDD.edge_profiles__grid_ggd,
grid_subset_index::Int,
value_field::Symbol=:values
Expand All @@ -275,8 +275,8 @@ Example:
get_n_e_sep = interp(dd.edge_profiles.ggd[1].electrons.density, grid_ggd, 16)
"""
function interp(
prop_arr::Vector{T},
grid_ggd::OMAS.edge_profiles__grid_ggd,
prop_arr::AbstractVector{T},
grid_ggd::IMASDD.edge_profiles__grid_ggd,
grid_subset_index::Int,
value_field::Symbol=:values,
) where {T <: edge_profiles__prop_on_subset}
Expand All @@ -286,7 +286,7 @@ function interp(
return interp(getfield(prop, value_field), space, subset)
end

function get_TPS_mats(grid_ggd::OMAS.edge_profiles__grid_ggd, grid_subset_index::Int)
function get_TPS_mats(grid_ggd::IMASDD.edge_profiles__grid_ggd, grid_subset_index::Int)
subset = get_grid_subset_with_index(grid_ggd, grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return get_TPS_mats(space, subset)
Expand All @@ -295,7 +295,7 @@ end
#! format off
"""
interp(
prop_arr::Vector{T},
prop_arr::AbstractVector{T},
TPS_mats::Tuple{Matrix{U}, Matrix{U}, Matrix{U}, Vector{Tuple{U, U}}},
grid_subset_index::Int,
value_field::Symbol=:values,
Expand All @@ -316,7 +316,7 @@ This will run faster has heavy matrix calculations will happen only once.
"""
#! format on
function interp(
prop_arr::Vector{T},
prop_arr::AbstractVector{T},
TPS_mats::Tuple{Matrix{U}, Matrix{U}, Matrix{U}, Vector{Tuple{U, U}}},
grid_subset_index::Int,
value_field::Val{V}=Val(:values),
Expand All @@ -330,7 +330,7 @@ const RHO_EXT_POS = [1.0001, 1.1, 5]
const RHO_EXT_NEG = [-5, -0.0001] # I guess this would be at a PF coil or something?

"""
interp(eqt::OMAS.equilibrium__time_slice)
interp(eqt::IMASDD.equilibrium__time_slice)
For a given equilibrium time slice, return a function that can be used to interpolate
from (r, z) space to rho (normalized toroidal flux coordinate)space.
Expand All @@ -339,7 +339,7 @@ Example:
rz2rho = interp(dd.equilibrium.time_slice[1])
rho = rz2rho.([(r, z) for r in 3:0.01:9, for z in -5:0.01:5])
"""
function interp(eqt::OMAS.equilibrium__time_slice)
function interp(eqt::IMASDD.equilibrium__time_slice)
p1 = eqt.profiles_1d
p2 = eqt.profiles_2d[1]
gq = eqt.global_quantities
Expand Down Expand Up @@ -370,7 +370,7 @@ end
"""
interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
prof::IMASDD.core_profiles__profiles_1d,
) where {T <: Real}
Expand All @@ -384,7 +384,7 @@ get_n_e(1) # Returns electron density at rho = 1 (separatix)
"""
function interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
prof::IMASDD.core_profiles__profiles_1d,
) where {T <: Real}
rho_prof = copy(prof.grid.rho_tor_norm)
length(prop) == length(rho_prof) ||
Expand All @@ -400,7 +400,7 @@ end
"""
interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
prof::IMASDD.core_profiles__profiles_1d,
rz2rho::Function,
)
Expand All @@ -418,7 +418,7 @@ get_n_e(5.0, 3.5) # Returns electron density at (R, Z) = (5.0, 3.5)
"""
function interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
prof::IMASDD.core_profiles__profiles_1d,
rz2rho::Function,
) where {T <: Real}
itp = interp(prop, prof)
Expand All @@ -431,8 +431,8 @@ end
"""
interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
eqt::OMAS.equilibrium__time_slice,
prof::IMASDD.core_profiles__profiles_1d,
eqt::IMASDD.equilibrium__time_slice,
) where {T <: Real}
Expand All @@ -449,8 +449,8 @@ get_n_e(5.0, 3.5) # Returns electron density at (R, Z) = (5.0, 3.5)
"""
function interp(
prop::Vector{T},
prof::OMAS.core_profiles__profiles_1d,
eqt::OMAS.equilibrium__time_slice,
prof::IMASDD.core_profiles__profiles_1d,
eqt::IMASDD.equilibrium__time_slice,
) where {T <: Real}
rz2rho = interp(eqt)
return interp(prop, prof, rz2rho)
Expand Down
Loading

0 comments on commit 238d675

Please sign in to comment.