Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final switch to IMASDD #41

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
14 changes: 7 additions & 7 deletions examples/plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"metadata": {},
"outputs": [],
"source": [
"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]"
"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,18 +146,18 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.4",
"display_name": "Julia 1.9.2",
"language": "julia",
"name": "julia-1.10"
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.4"
"version": "1.9.2"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
}
10 changes: 5 additions & 5 deletions examples/plotting_interferometer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"metadata": {},
"outputs": [],
"source": [
"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]"
"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.4",
"display_name": "Julia 1.9.2",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.4"
"version": "1.9.2"
},
"orig_nbformat": 4
},
Expand Down
5 changes: 2 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ env_with_cloned_repo r:
@echo "Cloning the repositories and generating Manifest.toml"
-dn=$(shell dirname $(shell pwd)); \
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()'
julia --project=. -e 'using Pkg; Pkg.rm(["IMASDD"]); 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", "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()'
julia --project=. -e 'using Pkg; Pkg.rm(["IMASDD"]); 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

import OMAS as IMASDD
using IMASDD: IMASDD

const inv_16pi = 1.0 / (16π)

Expand Down
97 changes: 87 additions & 10 deletions src/subset_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,76 @@ function project_prop_on_subset!(prop_arr::AbstractVector{T},
end
end

function deepcopy_subset(subset::IMASDD.edge_profiles__grid_ggd___grid_subset)
new_subset = IMASDD.edge_profiles__grid_ggd___grid_subset()

base = getfield(subset, :base)
new_base = getfield(new_subset, :base)
resize!(new_base, length(base))
for (ii, b) ∈ enumerate(base)
if !IMASDD.ismissing(b, :jacobian)
new_base[ii].jacobian = deepcopy(getfield(b, :jacobian))
end
if !IMASDD.ismissing(b, :tensor_contravariant)
new_base[ii].tensor_contravariant =
deepcopy(getfield(b, :tensor_contravariant))
end
if !IMASDD.ismissing(b, :tensor_covariant)
new_base[ii].tensor_covariant = deepcopy(getfield(b, :tensor_covariant))
end
end

if !IMASDD.ismissing(subset, :dimension)
new_subset.dimension = deepcopy(getfield(subset, :dimension))
end

element = getfield(subset, :element)
new_element = getfield(new_subset, :element)
resize!(new_element, length(element))
for (ii, ele) ∈ enumerate(element)
object = getfield(ele, :object)
new_object = getfield(new_element[ii], :object)
resize!(new_object, length(object))
for (jj, obj) ∈ enumerate(object)
if !IMASDD.ismissing(obj, :dimension)
new_object[jj].dimension = deepcopy(getfield(obj, :dimension))
end
if !IMASDD.ismissing(obj, :index)
new_object[jj].index = deepcopy(getfield(obj, :index))
end
if !IMASDD.ismissing(obj, :space)
new_object[jj].space = deepcopy(getfield(obj, :space))
end
end
end

identifier = getfield(subset, :identifier)
new_identifier = getfield(new_subset, :identifier)
if !IMASDD.ismissing(identifier, :index)
new_identifier.index = deepcopy(getfield(identifier, :index))
end
if !IMASDD.ismissing(identifier, :name)
new_identifier.name = deepcopy(getfield(identifier, :name))
end
if !IMASDD.ismissing(identifier, :description)
new_identifier.description = deepcopy(getfield(identifier, :description))
end

metric = getfield(subset, :metric)
new_metric = getfield(new_subset, :metric)
if !IMASDD.ismissing(metric, :jacobian)
new_metric.jacobian = deepcopy(getfield(metric, :jacobian))
end
if !IMASDD.ismissing(metric, :tensor_contravariant)
new_metric.tensor_contravariant =
deepcopy(getfield(metric, :tensor_contravariant))
end
if !IMASDD.ismissing(metric, :tensor_covariant)
new_metric.tensor_covariant = deepcopy(getfield(metric, :tensor_covariant))
end
return new_subset
end

"""
Base.:∈(
point::Tuple{Real, Real},
Expand Down Expand Up @@ -391,17 +461,18 @@ function Base.:∈(
)
r, z = point
subset, space = subset_of_space
dim = subset.element[1].object[1].dimension
nodes = space.objects_per_dimension[1].object
edges = space.objects_per_dimension[2].object
dim = getfield(getfield(getfield(subset, :element)[1], :object)[1], :dimension)
opd = getfield(space, :objects_per_dimension)
nodes = getfield(opd[1], :object)
edges = getfield(opd[2], :object)
if dim == 3
subset_bnd = IMASDD.edge_profiles__grid_ggd___grid_subset()
subset_bnd.element = get_subset_boundary(space, subset)
elseif dim == 2
subset_bnd = subset
elseif dim == 1
for ele ∈ subset.element
node = nodes[ele.object[1].index]
for ele ∈ getfield(subset, :element)
node = nodes[getfield(getfield(ele, :object)[1], :index)]
if node.geometry[1] == r && node.geometry[2] == z
return true
end
Expand All @@ -412,12 +483,18 @@ function Base.:∈(
end
# Count number of times an upward going ray from (r,z) intersects the boundary
count = 0
for ele ∈ subset_bnd.element
edge = edges[ele.object[1].index]
r_max = maximum(nodes[node].geometry[1] for node ∈ edge.nodes)
r_min = minimum(nodes[node].geometry[1] for node ∈ edge.nodes)
for ele ∈ getfield(subset_bnd, :element)
edge = edges[getfield(getfield(ele, :object)[1], :index)]
edge_nodes_r = zeros(2)
edge_nodes_z = zeros(2)
for (ii, node) ∈ enumerate(getfield(edge, :nodes))
edge_nodes_r[ii] = getfield(nodes[node], :geometry)[1]
edge_nodes_z[ii] = getfield(nodes[node], :geometry)[2]
end
r_max = maximum(edge_nodes_r)
r_min = minimum(edge_nodes_r)
if r_min <= r < r_max
z_max = maximum(nodes[node].geometry[2] for node ∈ edge.nodes)
z_max = maximum(edge_nodes_z)
if z < z_max
count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GGDUtils: interp, get_kdtree, project_prop_on_subset!, get_grid_subset
import OMAS as IMASDD
using IMASDD: IMASDD
import Statistics: mean
using Test
using ArgParse: ArgParse
Expand Down
83 changes: 83 additions & 0 deletions test/speedtest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import GGDUtils: interp, get_kdtree, project_prop_on_subset!, get_grid_subset, IMASDD

println("-----------------------------------------------------------------------------")
print("json2imas() time with compilation: ")
@time ids = IMASDD.json2imas(
"$(@__DIR__)/../samples/time_dep_edge_profiles_last_step_only.json",
)
print("json2imas() time (true runtime): ")
@time ids = IMASDD.json2imas(
"$(@__DIR__)/../samples/time_dep_edge_profiles_last_step_only.json",
)

println("-----------------------------------------------------------------------------")
n_e = ids.edge_profiles.ggd[1].electrons.density[1];
grid_ggd = ids.edge_profiles.grid_ggd[1];
space = grid_ggd.space[1]
print("interp(prop, grid_ggd) time with compilation: ")
@time get_n_e = interp(n_e, grid_ggd)
print("interp(prop, grid_ggd) (true runtime): ")
@time get_n_e = interp(n_e, grid_ggd)

println("-----------------------------------------------------------------------------")
subset = get_grid_subset(grid_ggd, 5)

print("interp(prop_arr, space, subset) time with compilation: ")
@time get_n_e = interp(ids.edge_profiles.ggd[1].electrons.density, space, subset)
print("interp(prop_arr, space, subset) time (true runtime): ")
@time get_n_e = interp(ids.edge_profiles.ggd[1].electrons.density, space, subset)

println("-----------------------------------------------------------------------------")
print("interp(prop_arr, grid_ggd, grid_subset_index) time with compilation: ")
@time get_n_e = interp(ids.edge_profiles.ggd[1].electrons.density, grid_ggd, 5)
print("interp(prop_arr, grid_ggd, grid_subset_index) time (true runtime): ")
@time get_n_e = interp(ids.edge_profiles.ggd[1].electrons.density, grid_ggd, 5)

println("-----------------------------------------------------------------------------")
kdtree = get_kdtree(space)
print("interp(prop_arr, kdtree) time with compilation: ")
@time get_T_e = interp(ids.edge_profiles.ggd[1].electrons.temperature[1].values, kdtree)
print("interp(prop_arr, kdtree) time (true runtime): ")
@time get_T_e = interp(ids.edge_profiles.ggd[1].electrons.temperature[1].values, kdtree)

println("-----------------------------------------------------------------------------")
prop = ids.edge_profiles.ggd[1].electrons.density
# All cells
from_subset = get_grid_subset(ids.edge_profiles.grid_ggd[1], 5)
# separatix
to_subset = get_grid_subset(ids.edge_profiles.grid_ggd[1], 16)
print(
"project_prop_on_subset!(prop, from_subset, to_subset, space) time with compilation: ",
)
@time separatix_centers, values_at_separatix =
project_prop_on_subset!(prop, from_subset, to_subset, space)
print(
"project_prop_on_subset!(prop, from_subset, to_subset, space) time (true runtime): ",
)
@time separatix_centers, values_at_separatix =
project_prop_on_subset!(prop, from_subset, to_subset, space)

println("-----------------------------------------------------------------------------")
subset_core =
get_grid_subset(ids.edge_profiles.grid_ggd[1], 22)
print("project_prop_on_subset!(prop, from_subset, subset_core) time with compilation: ")
@time core_element_inds, values_at_core =
project_prop_on_subset!(prop, from_subset, subset_core)
print("project_prop_on_subset!(prop, from_subset, subset_core) time (true runtime): ")
@time core_element_inds, values_at_core =
project_prop_on_subset!(prop, from_subset, subset_core)

println("-----------------------------------------------------------------------------")
subset_corebnd = get_grid_subset(grid_ggd, 15)
subset_sol = get_grid_subset(grid_ggd, 23)
subset_odr = get_grid_subset(grid_ggd, 24)

print("test ∈ (edges) time with compilation: ")
@time (6.0, 0.0) ∈ (subset_corebnd, space)
print("test ∈ (edges) time (true runtime): ")
@time (6.0, 0.0) ∈ (subset_corebnd, space)

print("test ∈ (cells) time with compilation: ")
@time (6.0, 4.0) ∈ (subset_sol, space)
print("test ∈ (cells) time (true runtime): ")
@time (6.0, 4.0) ∈ (subset_sol, space)
Loading