Skip to content

Commit

Permalink
Merge pull request #78 from ProjectTorreyPines/bug_fix
Browse files Browse the repository at this point in the history
Quick bug fix: subset_do does not need space kwarg

space keyword argument was being used in subset_do when use_nodes was true but this requried unnecessary creation of empty dummy input when use_nodes was not true.

With _parent fields in IMASdd ids, we can actually get the space object corresponding to a grid subset. So new functions have been added to get the parent objects:

get_grid_ggd: gets parent grid_ggd from space or grid_subset
get_space: gets corresponding space of a grid_subset from the parent.

New tests for testing subset_tools have been added as well.

Since the previous 3.0.0 has a bug because of this, minor version has been rolled up.
  • Loading branch information
anchal-physics authored Feb 26, 2025
2 parents d88fbe9 + 443eddd commit 52f4fb9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 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 <guptaa@fusion.gat.com>"]
version = "3.0.0"
version = "3.1.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ get_subset_space
get_grid_subset
get_subset_boundary_inds
get_subset_boundary
get_grid_ggd
get_space
subset_do
get_subset_centers
project_prop_on_subset!
Expand Down
35 changes: 27 additions & 8 deletions src/subset_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export get_subset_space
export get_grid_subset
export get_subset_boundary_inds
export get_subset_boundary
export get_grid_ggd
export get_space
export subset_do
export get_subset_centers
export project_prop_on_subset!
Expand Down Expand Up @@ -162,26 +164,43 @@ function get_subset_boundary(
return ret_subset
end

"""
get_grid_ggd(subset::Union{all__grid_subset, all__space})::all__grid_ggd
Get the parent grid_ggd of a `grid_subset` or `space` object.
"""
function get_grid_ggd(subset::Union{all__grid_subset, all__space})::all__grid_ggd
return getfield(getfield(subset, :_parent).value, :_parent).value
end

"""
get_space_from_subset(subset::all__grid_subset)::all__space
Get the corresponding space in parent grid_ggd for a grid_subset object.
"""
function get_space(subset::all__grid_subset)::all__space
grid_ggd = get_grid_ggd(subset)
return grid_ggd.space[subset.element[1].object[1].space]
end

"""
subset_do(
set_operator,
itrs::Vararg{all__grid_subset};
space::all__space,
use_nodes=false,
)::all__grid_subset
Function to perform any set operation (intersect, union, setdiff etc.) on
subset.element to generate a list of elements to go to subset object. If use_nodes is
true, the set operation will be applied on the set of nodes from subset.element, space
argument is required for this.
true, the set operation will be applied on the set of nodes from subset.element.
"""
function subset_do(
set_operator,
itrs::Vararg{all__grid_subset};
space::all__space,
use_nodes=false,
)::all__grid_subset
if use_nodes
space = get_space(itrs[1])
ele_inds = set_operator(
[
union([
Expand All @@ -195,10 +214,10 @@ function subset_do(
ele_inds = set_operator(
[[ele.object[1].index for ele subset.element] for subset itrs]...,
)
dim = itrs[1][1].object[1].dimension
dim = itrs[1].element[1].object[1].dimension
end
ret_subset = typeof(itrs[1][1])()
space_number = itrs[1][1].object[1].space
ret_subset = typeof(itrs[1])()
space_number = itrs[1].element[1].object[1].space
add_subset_element!(ret_subset, space_number, dim, ele_inds)
return ret_subset
end
Expand Down Expand Up @@ -404,7 +423,7 @@ Faster deepcopy function for grid_subset object. This function is used to create
copy of a grid_subset object bypassing several checks performed by IMASdd.
"""
function deepcopy_subset(subset::all__grid_subset)::all__grid_subset
new_subset = all__grid_subset()
new_subset = typeof(subset)()

base = getfield(subset, :base)
new_base = getfield(new_subset, :base)
Expand Down
60 changes: 59 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import IMASggd: interp, get_kdtree, project_prop_on_subset!, get_grid_subset
import IMASggd:
interp, get_kdtree, project_prop_on_subset!, get_grid_subset, get_grid_ggd,
get_subset_boundary, subset_do, deepcopy_subset
using IMASdd: IMASdd
import Statistics: mean
using Test
Expand All @@ -22,6 +24,9 @@ function parse_commandline()
["--interpeqt"],
Dict(:help => "Test interpolation of equilibrium time slice",
:action => :store_true),
["--subset_tools"],
Dict(:help => "Test subset tools",
:action => :store_true),
)
args = ArgParse.parse_args(s)
if !any(values(args)) # If no flags are set, run all tests
Expand Down Expand Up @@ -157,6 +162,59 @@ if args["projection"]
end
end

if args["subset_tools"]
@testset "test subset_tools" begin
grid_ggd = ids.edge_profiles.grid_ggd[1]
space = grid_ggd.space[1]

@test grid_ggd == get_grid_ggd(space)

subset_core = get_grid_subset(grid_ggd, 22)
subset_sol = get_grid_subset(grid_ggd, 23)
subset_odr = get_grid_subset(grid_ggd, 24)
subset_idr = get_grid_subset(grid_ggd, 25)
subset_otarget = get_grid_subset(grid_ggd, 13)
subset_itarget = get_grid_subset(grid_ggd, 14)

subset_corebnd = get_grid_subset(grid_ggd, 15)
subset_separatrix = get_grid_subset(grid_ggd, 16)
subset_pfrcut = get_grid_subset(grid_ggd, 8)
subset_otsep = get_grid_subset(grid_ggd, 103)
subset_itsep = get_grid_subset(grid_ggd, 104)

core_bdry = get_subset_boundary(space, subset_core)
sol_bdry = get_subset_boundary(space, subset_sol)
idr_bdry = get_subset_boundary(space, subset_idr)
odr_bdry = get_subset_boundary(space, subset_odr)

@test subset_pfrcut.element ==
subset_do(intersect, idr_bdry, odr_bdry).element
@test subset_corebnd.element ==
subset_do(setdiff, core_bdry, sol_bdry).element
@test subset_separatrix.element ==
subset_do(intersect, sol_bdry,
subset_do(union, core_bdry, odr_bdry, idr_bdry)).element
@test subset_otsep.element ==
subset_do(
intersect,
subset_separatrix,
subset_otarget;
use_nodes=true,
).element
@test subset_itsep.element ==
subset_do(
intersect,
subset_separatrix,
subset_itarget;
use_nodes=true,
).element

sol_copy = deepcopy_subset(subset_sol)

@test subset_sol == deepcopy_subset(subset_sol)
end
end

if args["in"]
@testset "test ∈" begin
grid_ggd = ids.edge_profiles.grid_ggd[1]
Expand Down

2 comments on commit 52f4fb9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release notes:

Merge pull request #78 from ProjectTorreyPines/bug_fix

Quick bug fix: subset_do does not need space kwarg

space keyword argument was being used in subset_do when use_nodes was true but this requried unnecessary creation of empty dummy input when use_nodes was not true.

With _parent fields in IMASdd ids, we can actually get the space object corresponding to a grid subset. So new functions have been added to get the parent objects:

get_grid_ggd: gets parent grid_ggd from space or grid_subset
get_space: gets corresponding space of a grid_subset from the parent.

New tests for testing subset_tools have been added as well.

Since the previous 3.0.0 has a bug because of this, minor version has been rolled up.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/125911

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.1.0 -m "<description of version>" 52f4fb987e4d7edfcf5ac3f2209aa5bfdc4ab3d3
git push origin v3.1.0

Please # to comment.