Skip to content

Commit

Permalink
Expanding acces of functions to all grid_ggd
Browse files Browse the repository at this point in the history
grid_ggd like structure is very common in IMAS data dictionary and
is used in various different sub dictionaries such as edge_profiles,
core_profiles, radiation etc.

The functions present in this repo are very general and should be
applciable to all these other types as well since the inherent
geometry withing the grid_ggd structures remain the same.

The get_types_with function has been improved to take much less time
and does not involve creating dummy objects any more. This funciton
stably outputs a list of types that are used to create following
new union of types:

all__grid_ggd: Union of all grid_ggd types
all__space: Union of all grid_ggd[:].space types
all__grid_subset: Union of all grid_ggd[:].grid_subset types
all__grid_subset_prop: Union of all ggd[:].*** types that have grid_subset_index as a field. These types typically store values corresponding to a particular grid_subset.

The subset tools, interpolations, and recipes have been modified to expand access to all types.
It is notable that some functions like get_subset_space() and subset_do()
have been changed in signature to take in subset objects and operate on their element array
instead of directly taking in the element array. This is a BREAKING change and thus
this branch will require version roll up.

Document has been updated as well.

More functions' output types have been fixed.

Note that there is an increased compilation time due to the expansion but execution time remains the same.
  • Loading branch information
anchal-physics committed Feb 26, 2025
1 parent 5d77061 commit 6aa0cab
Show file tree
Hide file tree
Showing 8 changed files with 787 additions and 317 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IMASggd"
uuid = "b7b5e640-9b39-4803-84eb-376048795def"
authors = ["Anchal Gupta <[email protected]>"]
version = "2.0.1"
version = "3.0.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand All @@ -17,7 +17,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
ArgParse = "1"
ColorSchemes = "3"
IMASdd = "2, 3"
IMASdd = "2, 3, 4"
Interpolations = "0.15"
NearestNeighbors = "0.4"
RecipesBase = "1"
Expand Down
18 changes: 14 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,24 @@ get_prop_with_grid_subset_index
get_types_with
```

This function has been used to create following types that are used in this module and
can be imported for further use.

```@docs
IMASggd.all__grid_ggd
IMASggd.all__space
IMASggd.all__grid_subset
IMASggd.all__grid_subset_prop
```

## Plot recipes

Several plot recipes have been defined for easy visualization.
```@docs
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.edge_profiles__grid_ggd___space)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.edge_profiles__grid_ggd___space, ::IMASggd.IMASdd.edge_profiles__grid_ggd___grid_subset)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.edge_profiles__grid_ggd, ::IMASggd.IMASdd.IDSvectorElement)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::AbstractVector{<:IMASggd.IMASdd.edge_profiles__grid_ggd}, ::IMASggd.IMASdd.IDSvectorElement)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.all__space)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.all__space, ::IMASggd.all__grid_subset)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.all__grid_ggd, ::IMASggd.all__grid_subset_prop)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::AbstractVector{<:IMASggd.all__grid_ggd}, ::IMASggd.all__grid_subset_prop)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.interferometer)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.interferometer__channel)
RecipesBase.apply_recipe(::Dict{Symbol,Any}, ::IMASggd.IMASdd.interferometer__channel___line_of_sight)
Expand Down
15 changes: 7 additions & 8 deletions examples/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"[email protected]:ProjectTorreyPines/IMASdd.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")\n",
"Pkg.add(\"LaTeXStrings\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -44,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -115,7 +114,7 @@
"gr() # Fast and can save pdf\n",
"# plotlyjs() # Use for interactive plot, can only save png\n",
"\n",
"n_e = IMASggd.get_prop_with_grid_subset_index(dd.edge_profiles.ggd[1].electrons.density, 5)\n",
"n_e = IMASggd.get_prop_with_grid_subset_index(dd.edge_profiles.ggd[1].electrons.density, -5)\n",
"plot(dd.edge_profiles.grid_ggd, n_e, colorbar_title=\"Electrons density / \" * L\"m^{-3}\",\n",
" left_margin=10Plots.pt)"
]
Expand Down Expand Up @@ -146,18 +145,18 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"display_name": "Julia 1.10.4",
"language": "julia",
"name": "julia-1.9"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
"version": "1.10.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
}
19 changes: 9 additions & 10 deletions examples/plotting_interferometer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
"source": [
"using Pkg\n",
"Pkg.activate(\"./\")\n",
"Pkg.add(url=\"[email protected]:ProjectTorreyPines/IMASdd.jl.git\")\n",
"Pkg.develop(path=\"../\")\n",
"Pkg.add(\"Plots\")"
"# Pkg.develop(path=\"../\")\n",
"# Pkg.add(\"Plots\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -49,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -217,7 +216,7 @@
"source": [
"gr()\n",
"\n",
"n_e = IMASggd.get_prop_with_grid_subset_index(ids.edge_profiles.ggd[1].electrons.density, 5)\n",
"n_e = IMASggd.get_prop_with_grid_subset_index(ids.edge_profiles.ggd[1].electrons.density, -5)\n",
"plot(ids.edge_profiles.grid_ggd, n_e, colorbar_title=\"Electrons density / m^(-3)\", left_margin=10Plots.pt)\n",
"plot!(space)\n",
"plot!(ids.interferometer, legend=true, size=[635, 900]) # Adding a size comment to make plot aspect ratio better"
Expand All @@ -226,18 +225,18 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"display_name": "Julia 1.10.4",
"language": "julia",
"name": "julia-1.9"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
"version": "1.10.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
}
64 changes: 32 additions & 32 deletions src/interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export get_kdtree
export get_TPS_mats

"""
get_kdtree(space::IMASdd.edge_profiles__grid_ggd___space)
get_kdtree(space::all__space)
Get a KDTree for all the cells in the space for search for nearest neighbours.
"""
function get_kdtree(space::IMASdd.edge_profiles__grid_ggd___space)
function get_kdtree(space::all__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 @@ -25,15 +25,15 @@ end

"""
get_kdtree(
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
)
Get a KDTree for a subset of the space for search for nearest neighbours.
"""
function get_kdtree(
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
)
subset_centers = get_subset_centers(space, subset)
return KDTree([SVector{2}(sc) for sc subset_centers]; leafsize=10)
Expand Down Expand Up @@ -178,15 +178,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::IMASdd.edge_profiles__grid_ggd___space)
function get_TPS_mats(space::all__space)

Check warning on line 181 in src/interpolations.jl

View check run for this annotation

Codecov / codecov/patch

src/interpolations.jl#L181

Added line #L181 was not covered by tests
nodes = [Tuple(node.geometry) for node space.objects_per_dimension[1].object]
return get_TPS_mats(nodes)
end

"""
interp(
prop_values::Vector{T},
space::IMASdd.edge_profiles__grid_ggd___space
space::all__space
) where {T <: Real}
If the whole space is provided instead of a kdtree, calculate the kdtree for whole
Expand All @@ -195,40 +195,40 @@ of the space.
"""
function interp(
prop_values::Vector{T},
space::IMASdd.edge_profiles__grid_ggd___space,
space::all__space,
) where {T <: Real}
return interp(prop_values, get_TPS_mats(space))
end

function get_TPS_mats(
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
)
return get_TPS_mats(get_subset_centers(space, subset))
end

"""
interp(
prop_values::Vector{Real},
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset
space::all__space,
subset::all__grid_subset
)
If a subset of the space is provided, calculate the kdtree for the subset. In this case
it is assumed that the property values are provided for each element of the subset.
"""
function interp(
prop_values::Vector{T},
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
) where {T <: Real}
return interp(prop_values, get_TPS_mats(space, subset))
end

"""
interp(
prop::edge_profiles__prop_on_subset,
grid_ggd::IMASdd.edge_profiles__grid_ggd,
prop::all__grid_subset_prop,
grid_ggd::all__grid_ggd,
value_field::Symbol=:values
)
Expand All @@ -241,8 +241,8 @@ 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::IMASdd.edge_profiles__grid_ggd,
prop::all__grid_subset_prop,
grid_ggd::all__grid_ggd,
value_field::Symbol=:values,
)
subset = get_grid_subset(grid_ggd, prop.grid_subset_index)
Expand All @@ -253,10 +253,10 @@ end
"""
interp(
prop_arr::AbstractVector{T},
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
value_field::Symbol=:values
) where {T <: edge_profiles__prop_on_subset}
) where {T <: all__grid_subset_prop}
Example:
Expand All @@ -267,21 +267,21 @@ get_electron_density = interp(dd.edge_profiles.ggd[1].electrons.density, space,
"""
function interp(
prop_arr::AbstractVector{T},
space::IMASdd.edge_profiles__grid_ggd___space,
subset::IMASdd.edge_profiles__grid_ggd___grid_subset,
space::all__space,
subset::all__grid_subset,
value_field::Symbol=:values,
) where {T <: edge_profiles__prop_on_subset}
) where {T <: all__grid_subset_prop}
prop = get_prop_with_grid_subset_index(prop_arr, subset.identifier.index)
return interp(getfield(prop, value_field), space, subset)
end

"""
interp(
prop_arr::AbstractVector{T},
grid_ggd::IMASdd.edge_profiles__grid_ggd,
grid_ggd::all__grid_ggd,
grid_subset_index::Int,
value_field::Symbol=:values
) where {T <: edge_profiles__prop_on_subset}
) where {T <: all__grid_subset_prop}
Example:
Expand All @@ -291,17 +291,17 @@ get_n_e_sep = interp(dd.edge_profiles.ggd[1].electrons.density, grid_ggd, 16)
"""
function interp(
prop_arr::AbstractVector{T},
grid_ggd::IMASdd.edge_profiles__grid_ggd,
grid_ggd::all__grid_ggd,
grid_subset_index::Int,
value_field::Symbol=:values,
) where {T <: edge_profiles__prop_on_subset}
) where {T <: all__grid_subset_prop}
prop = get_prop_with_grid_subset_index(prop_arr, grid_subset_index)
subset = get_grid_subset(grid_ggd, grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return interp(getfield(prop, value_field), space, subset)
end

function get_TPS_mats(grid_ggd::IMASdd.edge_profiles__grid_ggd, grid_subset_index::Int)
function get_TPS_mats(grid_ggd::all__grid_ggd, grid_subset_index::Int)

Check warning on line 304 in src/interpolations.jl

View check run for this annotation

Codecov / codecov/patch

src/interpolations.jl#L304

Added line #L304 was not covered by tests
subset = get_grid_subset(grid_ggd, grid_subset_index)
space = grid_ggd.space[subset.element[1].object[1].space]
return get_TPS_mats(space, subset)
Expand All @@ -313,7 +313,7 @@ end
TPS_mats::Tuple{Matrix{U}, Matrix{U}, Matrix{U}, Vector{Tuple{U, U}}},
grid_subset_index::Int,
value_field::Val{V}=Val(:values),
) where {T <: edge_profiles__prop_on_subset, U <: Real, V}
) where {T <: all__grid_subset_prop, U <: Real, V}
Same use case as above but allows one to reuse previously calculated TPS matrices.
Expand All @@ -335,7 +335,7 @@ function interp(
TPS_mats::Tuple{Matrix{U}, Matrix{U}, Matrix{U}, Vector{Tuple{U, U}}},
grid_subset_index::Int,
value_field::Val{V}=Val(:values),
) where {T <: edge_profiles__prop_on_subset, U <: Real, V}
) where {T <: all__grid_subset_prop, U <: Real, V}
prop = get_prop_with_grid_subset_index(prop_arr, grid_subset_index)
field = getfield(prop, V)
return interp(field, TPS_mats)
Expand Down
Loading

0 comments on commit 6aa0cab

Please sign in to comment.