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 #32

Merged
merged 6 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 @@ DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
GGDUtils = "b7b5e640-9b39-4803-84eb-376048795def"
IMASDD = "06b86afa-9f21-11ec-2ef8-e51b8960cfc5"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
OMAS = "91cfaa06-6526-4804-8666-b540b3feef2f"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
5 changes: 2 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ 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}; \
git clone "git@github.com:ProjectTorreyPines/GGDUtils.jl.git" ../GGDUtils$${ext}; \
julia --project=. -e 'using Pkg; Pkg.rm(["OMAS", "IMASDD", "GGDUtils"]); Pkg.develop(path="../OMAS'$${ext}'"); Pkg.develop(path="../IMASDD'$${ext}'"); Pkg.develop(path="../GGDUtils'$${ext}'"); Pkg.instantiate()'
julia --project=. -e 'using Pkg; Pkg.rm(["IMASDD", "GGDUtils"]); Pkg.develop(path="../IMASDD'$${ext}'"); Pkg.develop(path="../GGDUtils'$${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", "GGDUtils"]); 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.add(url="git@github.com:ProjectTorreyPines/GGDUtils.jl.git", rev="master"); Pkg.instantiate()'
julia --project=. -e 'using Pkg; Pkg.rm(["IMASDD", "GGDUtils"]); Pkg.add(url="git@github.com:ProjectTorreyPines/IMASDD.jl.git", rev="master"); Pkg.add(url="git@github.com:ProjectTorreyPines/GGDUtils.jl.git", rev="master"); Pkg.instantiate()'

clean:
@echo "Deleting Manifest.toml"
Expand Down
13 changes: 8 additions & 5 deletions src/SOLPS2IMAS.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module SOLPS2IMAS

using Revise
import OMAS as IMASDD
using IMASDD: IMASDD
using NCDatasets: Dataset, dimnames
using YAML: load_file as YAML_load_file
using DelimitedFiles: readdlm
import GGDUtils: add_subset_element!, get_grid_subset, get_subset_boundary,
get_subset_space, subset_do
get_subset_space, subset_do, deepcopy_subset

export read_b2_output
export solps2imas
Expand Down Expand Up @@ -288,6 +288,9 @@ function solps2imas(
resize!(edges, edge_ind)
edges[edge_ind].nodes = edge_nodes
resize!(edges[edge_ind].boundary, 2)
for bnd ∈ edges[edge_ind].boundary
bnd.neighbours = Int64[]
end
for (ii, edge_bnd) ∈ enumerate(edges[edge_ind].boundary)
edge_bnd.index = edge_nodes[ii]
end
Expand Down Expand Up @@ -509,8 +512,9 @@ function solps2imas(
resize!(grid_ggd.grid_subset, cur_no_subsets + 12)
# Copy all B2.5 nodes, faces, edges, cells to grid_subset with negative indices
for (ii, gsi) ∈ enumerate([1, 2, 5])
grid_ggd.grid_subset[cur_no_subsets+ii] =
deepcopy(get_grid_subset(grid_ggd, gsi))
grid_ggd.grid_subset[cur_no_subsets+ii] = deepcopy_subset(
get_grid_subset(grid_ggd, gsi),
)
grid_ggd.grid_subset[cur_no_subsets+ii].identifier.index = -gsi
grid_ggd.grid_subset[cur_no_subsets+ii].identifier.name *= "_B2.5"
gsi_ch[gsi] = -gsi
Expand Down Expand Up @@ -596,7 +600,6 @@ function solps2imas(
resize!(cells, length(cells) + 1)
this_cell_ind = length(cells)
fntri_inds[fntri] = this_cell_ind
resize!(cells[this_cell_ind].nodes, 3)
cells[this_cell_ind].nodes = [
fnode_inds[fntriIndNodes[fntri, 2]],
fnode_inds[fntriIndNodes[fntri, 3]],
Expand Down
23 changes: 13 additions & 10 deletions src/solps_mesh_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function search_points(nodes, r, z; tol=0)
# If an index remains at 0, it means the point in question was not found
for j ∈ 1:n
for i ∈ eachindex(nodes)
rn = nodes[i].geometry[1]
zn = nodes[i].geometry[2]
rn, zn = getfield(nodes[i], :geometry)
# zn = nodes[i].geometry[2]
if abs(rn - r[j]) <= tol && abs(zn - z[j]) <= tol
indices[j] = i
break
Expand All @@ -60,10 +60,11 @@ search if an edge with nodes as edge_nodes already exists
"""
function search_edges(edges, edge_nodes)
for ii ∈ eachindex(edges)
if edge_nodes[1] == edges[ii].nodes[1] && edge_nodes[2] == edges[ii].nodes[2]
edges_ii_nodes = getfield(edges[ii], :nodes)
if edge_nodes[1] == edges_ii_nodes[1] && edge_nodes[2] == edges_ii_nodes[2]
return ii
elseif edge_nodes[2] == edges[ii].nodes[1] &&
edge_nodes[1] == edges[ii].nodes[2]
elseif edge_nodes[2] == edges_ii_nodes[1] &&
edge_nodes[1] == edges_ii_nodes[2]
return ii
end
end
Expand Down Expand Up @@ -169,8 +170,9 @@ function attach_neightbours(cells, edges, gmtry, it)
for neighbour_ind ∈ get_neighbour_inds(ic, gmtry, it)
for boundary ∈ cell.boundary
for neighbour_boundary ∈ cells[neighbour_ind].boundary
if boundary.index == neighbour_boundary.index &&
neighbour_ind ∉ boundary.neighbours
if getfield(boundary, :index) ==
getfield(neighbour_boundary, :index) &&
neighbour_ind ∉ getfield(boundary, :neighbours)
append!(boundary.neighbours, neighbour_ind)
end
end
Expand All @@ -188,10 +190,11 @@ function attach_neightbours(cells, edges, gmtry, it)
end
setdiff!(neighbour_edge_inds, edge_ind)
for neighbour_edge_ind ∈ neighbour_edge_inds
for edge_bnd ∈ edges[edge_ind].boundary
for edge_bnd ∈ getfield(edges[edge_ind], :boundary)
for neighbour_edge_bnd ∈ edges[neighbour_edge_ind].boundary
if edge_bnd.index == neighbour_edge_bnd.index &&
neighbour_edge_ind ∉ edge_bnd.neighbours
if getfield(edge_bnd, :index) ==
getfield(neighbour_edge_bnd, :index) &&
neighbour_edge_ind ∉ getfield(edge_bnd, :neighbours)
append!(edge_bnd.neighbours, neighbour_edge_ind)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using SOLPS2IMAS: SOLPS2IMAS
using Test
using YAML: load_file as YAML_load_file
using ArgParse: ArgParse
import OMAS as IMASDD
using IMASDD: IMASDD
import SOLPS2IMAS: get_grid_subset

allowed_rtol = 1e-4
Expand Down
14 changes: 14 additions & 0 deletions test/speedtest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using SOLPS2IMAS: SOLPS2IMAS

println("-----------------------------------------------------------------------------")
b2gmtry = "$(@__DIR__)/../samples/b2fgmtry"
b2output = "$(@__DIR__)/../samples/b2time.nc"
b2mn = "$(@__DIR__)/../samples/b2mn.dat"
fort = (
"$(@__DIR__)/../samples/fort.33",
"$(@__DIR__)/../samples/fort.34",
"$(@__DIR__)/../samples/fort.35")
print("solps2imas(b2gmtry, b2output; b2mn, fort) time with compilation: ")
@time dd = SOLPS2IMAS.solps2imas(b2gmtry, b2output; b2mn, fort);
print("solps2imas(b2gmtry, b2output; b2mn, fort) time (true runtime): ")
@time dd = SOLPS2IMAS.solps2imas(b2gmtry, b2output; b2mn, fort);
Loading