From 0b5cd541182bd322efe968f600237205786cb70e Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Sat, 7 Oct 2023 15:21:46 -0700 Subject: [PATCH 1/4] Quick bug fix project_prop_on_subset was not working properly when the property values are not tagged as values but some other name. Added a new argument for that. Also notices that interp(prop_values::Vector{T}, space::OMAS.edge_profiles__grid_ggd___space) had a typo in return call and would have failed. --- src/interpolations.jl | 2 +- src/subset_tools.jl | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/interpolations.jl b/src/interpolations.jl index ef1ead5..f6094c1 100644 --- a/src/interpolations.jl +++ b/src/interpolations.jl @@ -152,7 +152,7 @@ function interp( space::OMAS.edge_profiles__grid_ggd___space, ) where {T <: Real} nodes = [Tuple(node.geometry) for node ∈ space.objects_per_dimension[1].object] - return interp(prop, nodes) + return interp(prop_values, nodes) end """ diff --git a/src/subset_tools.jl b/src/subset_tools.jl index 137ecb9..7be2e36 100644 --- a/src/subset_tools.jl +++ b/src/subset_tools.jl @@ -45,17 +45,17 @@ space: (optional) space object in grid_ggd is required only when from_subset is Returns: NOTE: This function ends in ! which means it updates prop argument in place. But for the additional utility, this function also returns a tuple -(to_subset_centers, to_prop.values) when from_subset dimension is greater than +(to_subset_centers, to_prop_values) when from_subset dimension is greater than to_subset dimension OR -(to_subset_ele_obj_inds, to_prop.values) when from_subset dimension is same as +(to_subset_ele_obj_inds, to_prop_values) when from_subset dimension is same as to_subset dimension) Descriptions: to_subset_centers: center of cells or center of edges of the to_subset where property values are defined and stored to_subset_ele_obj_inds: Indices of the elements of to_subset where property values are defined and stored -to_prop.values: The projected values of the properties added to prop object in a new +to_prop_values: The projected values of the properties added to prop object in a new instance """ #! format: on @@ -63,6 +63,7 @@ function project_prop_on_subset!(prop_arr::Vector{T}, from_subset::OMAS.edge_profiles__grid_ggd___grid_subset, to_subset::OMAS.edge_profiles__grid_ggd___grid_subset, space::OMAS.edge_profiles__grid_ggd___space, + value_field::Symbol=:values, ) where {T <: edge_profiles__prop_on_subset} if from_subset.element[1].object[1].dimension == to_subset.element[1].object[1].dimension @@ -79,10 +80,12 @@ function project_prop_on_subset!(prop_arr::Vector{T}, to_prop = prop_arr[end] to_prop.grid_index = from_prop.grid_index to_prop.grid_subset_index = to_subset.identifier.index - resize!(to_prop.values, length(to_subset.element)) + to_prop_values = getfield(to_prop, value_field) + from_prop_values = getfield(from_prop, value_field) + resize!(to_prop_values, length(to_subset.element)) prop_interp = interp(prop_arr, space, from_subset) - to_prop.values = prop_interp.(to_subset_centers) - return to_subset_centers, to_prop.values + to_prop_values = prop_interp.(to_subset_centers) + return to_subset_centers, to_prop_values else error("to_subset is higher dimensional than from_subset") end @@ -91,6 +94,7 @@ end function project_prop_on_subset!(prop_arr::Vector{T}, from_subset::OMAS.edge_profiles__grid_ggd___grid_subset, to_subset::OMAS.edge_profiles__grid_ggd___grid_subset, + value_field::Symbol=:values, ) where {T <: edge_profiles__prop_on_subset} from_prop = get_prop_with_grid_subset_index(prop_arr, from_subset.identifier.index) if isnothing(from_prop) @@ -102,6 +106,8 @@ function project_prop_on_subset!(prop_arr::Vector{T}, to_prop = prop_arr[end] to_prop.grid_index = from_prop.grid_index to_prop.grid_subset_index = to_subset.identifier.index + to_prop_values = getfield(to_prop, value_field) + from_prop_values = getfield(from_prop, value_field) from_subset_ele_obj_inds = [ele.object[1].index for ele ∈ from_subset.element] to_subset_ele_obj_inds = [ele.object[1].index for ele ∈ to_subset.element] if to_subset_ele_obj_inds ⊆ from_subset_ele_obj_inds @@ -115,10 +121,10 @@ function project_prop_on_subset!(prop_arr::Vector{T}, end end filtered_values = - [from_prop.values[from_ele_ind] for from_ele_ind ∈ from_ele_inds] - resize!(to_prop.values, length(filtered_values)) - to_prop.values = filtered_values - return to_subset_ele_obj_inds, to_prop.values + [from_prop_values[from_ele_ind] for from_ele_ind ∈ from_ele_inds] + resize!(to_prop_values, length(filtered_values)) + to_prop_values = filtered_values + return to_subset_ele_obj_inds, to_prop_values else error("to_subset does not lie entirely inside from_subset. Projection ", "not possible.", From eb5df0d67604d90be0493eea1f8c25f19201d0b8 Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Sat, 7 Oct 2023 15:36:28 -0700 Subject: [PATCH 2/4] Add option of using which interp method In project_prop_on_subset!, when the dimensions of to_subset is lower, then an interpolation is required. This commit adds an option to choose between thin plate spline (:thin_plate_spline) (slower, more accurate) and using KD trees (:kd_tree) (faster, less accurate). --- src/subset_tools.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/subset_tools.jl b/src/subset_tools.jl index 7be2e36..de09bbb 100644 --- a/src/subset_tools.jl +++ b/src/subset_tools.jl @@ -64,6 +64,8 @@ function project_prop_on_subset!(prop_arr::Vector{T}, to_subset::OMAS.edge_profiles__grid_ggd___grid_subset, space::OMAS.edge_profiles__grid_ggd___space, value_field::Symbol=:values, + interp_method=:thin_plate_spline, + interp_kwargs=Dict(), ) where {T <: edge_profiles__prop_on_subset} if from_subset.element[1].object[1].dimension == to_subset.element[1].object[1].dimension @@ -83,7 +85,14 @@ function project_prop_on_subset!(prop_arr::Vector{T}, to_prop_values = getfield(to_prop, value_field) from_prop_values = getfield(from_prop, value_field) resize!(to_prop_values, length(to_subset.element)) - prop_interp = interp(prop_arr, space, from_subset) + if interp_method == :thin_plate_spline + prop_interp = interp(prop_arr, space, from_subset) + elseif interp_method == :KDTree + prop_interp = + interp(from_prop, get_kdtree(space, from_subset; interp_kwargs...)) + else + error("Supported interpolation methods are :thin_plate_spline and :KDTree") + end to_prop_values = prop_interp.(to_subset_centers) return to_subset_centers, to_prop_values else From a0609cfe308c336934f24f18a42548a59578263a Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Sat, 7 Oct 2023 15:49:53 -0700 Subject: [PATCH 3/4] Making interp_method, interp_kwargs kwargs --- src/subset_tools.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subset_tools.jl b/src/subset_tools.jl index de09bbb..67886e3 100644 --- a/src/subset_tools.jl +++ b/src/subset_tools.jl @@ -63,7 +63,7 @@ function project_prop_on_subset!(prop_arr::Vector{T}, from_subset::OMAS.edge_profiles__grid_ggd___grid_subset, to_subset::OMAS.edge_profiles__grid_ggd___grid_subset, space::OMAS.edge_profiles__grid_ggd___space, - value_field::Symbol=:values, + value_field::Symbol=:values; interp_method=:thin_plate_spline, interp_kwargs=Dict(), ) where {T <: edge_profiles__prop_on_subset} From 8b13a5559f39ed99ddce6aa316af402bb5cf0f29 Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Sat, 7 Oct 2023 15:51:39 -0700 Subject: [PATCH 4/4] Bug fix while using kdtee for interp --- src/subset_tools.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/subset_tools.jl b/src/subset_tools.jl index 67886e3..5b269dd 100644 --- a/src/subset_tools.jl +++ b/src/subset_tools.jl @@ -88,8 +88,10 @@ function project_prop_on_subset!(prop_arr::Vector{T}, if interp_method == :thin_plate_spline prop_interp = interp(prop_arr, space, from_subset) elseif interp_method == :KDTree - prop_interp = - interp(from_prop, get_kdtree(space, from_subset; interp_kwargs...)) + prop_interp = interp( + from_prop_values, + get_kdtree(space, from_subset; interp_kwargs...), + ) else error("Supported interpolation methods are :thin_plate_spline and :KDTree") end