From 0a2aa17230b361c99c7ed3f8bed0b622274636e9 Mon Sep 17 00:00:00 2001 From: Orso Meneghini Date: Fri, 28 Jan 2022 00:29:13 -0800 Subject: [PATCH 1/2] radial_build --> build --- examples/radial_build.ipynb | 16465 ++++++++-------- src/actors.jl | 8 +- .../{radial_build_actor.jl => build_actor.jl} | 116 +- src/actors/coils_actor.jl | 56 +- 4 files changed, 8263 insertions(+), 8382 deletions(-) rename src/actors/{radial_build_actor.jl => build_actor.jl} (84%) diff --git a/examples/radial_build.ipynb b/examples/radial_build.ipynb index ebaa4938d..b569981d4 100644 --- a/examples/radial_build.ipynb +++ b/examples/radial_build.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "e56ba378-9548-4a88-94f7-cee508492153", "metadata": {}, "outputs": [ @@ -10,25 +10,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Coding/julia/FUSE`\n", - "┌ Info: Precompiling FUSE [e64856f0-3bb8-4376-b4b7-c03396503992]\n", - "└ @ Base loading.jl:1423\n" - ] - }, - { - "ename": "LoadError", - "evalue": "UndefVarError: τ not defined", - "output_type": "error", - "traceback": [ - "UndefVarError: τ not defined", - "", - "Stacktrace:", - " [1] top-level scope", - " @ :0", - " [2] eval", - " @ ./boot.jl:373 [inlined]", - " [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)", - " @ Base ./loading.jl:1196" + "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Coding/julia/FUSE`\n" ] } ], @@ -37,12 +19,12 @@ "Pkg.activate(\"..\")\n", "using Revise\n", "using FUSE\n", - "using Plots; gr();τ" + "using Plots; gr();" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 3, "id": "252534d3-5de2-43eb-a2eb-62976591e8f2", "metadata": {}, "outputs": [ @@ -52,93 +34,93 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", "\n" ] }, @@ -564,7 +546,7 @@ " Iterations: 36\n", " f(x) calls: 70\n", "\n", - " 2.637903 seconds (42.48 M allocations: 672.367 MiB, 1.58% gc time)\n", + " 7.352394 seconds (59.75 M allocations: 1.622 GiB, 3.29% gc time, 64.37% compilation time)\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_tor = 0.018538831972279315\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_pol = 1.026350289869195\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_normal = 1.8758347713832044\n", @@ -619,7 +601,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 4, "id": "aff8c803-64d8-460d-b0d0-98f08d6bf661", "metadata": {}, "outputs": [ @@ -629,87 +611,87 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n" + "\n" ] }, - "execution_count": 39, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -1686,7 +1668,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 5, "id": "56f20782-3539-4022-bc36-b0b41c3d4d9c", "metadata": {}, "outputs": [ @@ -1696,66 +1678,66 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" + "\n" ] }, "metadata": {}, @@ -5079,7 +5061,7 @@ "# initialize radial build IDS\n", "eq = dd.equilibrium\n", "cp = dd.core_profiles\n", - "rb = dd.radial_build\n", + "rb = dd.build\n", "\n", "FUSE.init(rb, eq, tf_shape_index=3, is_nuclear_facility=true, pf_inside_tf=false, pf_outside_tf=true);\n", "FUSE.init(cp, ejima=0.4);\n", @@ -5096,7 +5078,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 6, "id": "21d8b059-1b9c-4cde-afca-a5b67a1cb99e", "metadata": {}, "outputs": [ @@ -5104,20 +5086,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970015961342963\n", - "0.02970016184416926\n", - "0.02970016184416926\n", - "0.02970015961342963\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300441394294\n", + "0.05925300564940361\n", + "0.05925300564940361\n", + "0.05925300441394294\n", " * Status: success\n", "\n", " * Candidate solution\n", - " Final objective value: 2.970016e-02\n", + " Final objective value: 5.925300e-02\n", "\n", " * Found with\n", " Algorithm: Nelder-Mead\n", @@ -5135,14 +5117,14 @@ ], "source": [ "# initialize pf actor\n", - "pfoptactor = PFcoilsOptActor(dd.equilibrium, dd.radial_build, dd.pf_active, [6, 6]; coil_model=:simple)\n", + "pfoptactor = PFcoilsOptActor(dd.equilibrium, dd.build, dd.pf_active, [6, 6]; coil_model=:simple)\n", "FUSE.step(pfoptactor, λ_ψ=1E-2, λ_null=1E+2, λ_currents=1E5, verbose=true, symmetric=true, maxiter=10000, optimization_scheme=:static);\n", "FUSE.finalize(pfoptactor);" ] }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 7, "id": "51cd44f2-f994-4a44-a2ea-d9a3e25f05cc", "metadata": {}, "outputs": [ @@ -5152,90 +5134,90 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", - " \n", + " \n", + " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" + "\n" ] }, "metadata": {}, @@ -5247,167 +5229,155 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n" + "\n", + "\n" ] }, "metadata": {}, @@ -5419,4407 +5389,4267 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", - " \n", + " \n", + " \n", " \n", "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", + "\n", - "\n", + "\n", - "\n", + "\n", - "\n", + "\n", - "\n", + "\n", + "\n", + "\n", - "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n" + "\n", + "\n" ] }, "metadata": {}, @@ -9831,3523 +9661,3574 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", - " \n", + " \n", + " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", + "\n", - "\n", - "\n", - "\n", + "\n", + "\n", - "\n", - "\n", - "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", "\n", - " \n", - " \n", + " \n", + " \n", " \n", "\n", - "\n", + "\n", "\n", + "\" transform=\"translate(1884, 47)\"/>\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" + "\n" ] }, "metadata": {}, diff --git a/src/actors.jl b/src/actors.jl index 6f8a1725b..cbbe160c0 100644 --- a/src/actors.jl +++ b/src/actors.jl @@ -46,9 +46,9 @@ include("actors/coils_actor.jl") export PFcoilsOptActor -#= ============ =# -# Radial Build # -#= ============ =# -include("actors/radial_build_actor.jl") +#= ===== =# +# Build # +#= ===== =# +include("actors/build_actor.jl") export FluxSwingActor \ No newline at end of file diff --git a/src/actors/radial_build_actor.jl b/src/actors/build_actor.jl similarity index 84% rename from src/actors/radial_build_actor.jl rename to src/actors/build_actor.jl index ad1742214..79d711e2a 100644 --- a/src/actors/radial_build_actor.jl +++ b/src/actors/build_actor.jl @@ -13,13 +13,13 @@ function init(cp::IMAS.core_profiles; kw...) return cp end -#= ================= =# -# init radial_build # -#= ================= =# +#= ========== =# +# init build # +#= ========== =# """ - init(rb::IMAS.radial_build; layers...) + init(rb::IMAS.build; layers...) -Initialize radial_build IDS based on center stack layers (thicknesses) +Initialize build IDS based on center stack layers (thicknesses) NOTE: layer[:].type and layer[:].material follows from naming of layers * 0 ...gap... : vacuum @@ -34,8 +34,8 @@ layer[:].hfs is set depending on if "hfs" or "lfs" appear in the name layer[:].identifier is created as a hash of then name removing "hfs" or "lfs" """ -function init(rb::IMAS.radial_build; layers...) - # empty radial build IDS +function init(rb::IMAS.build; layers...) + # empty build IDS empty!(rb) # assign layers resize!(rb.layer, length([layer_name for (layer_name, layer_thickness) in layers if layer_thickness >= 0.0])) @@ -75,18 +75,18 @@ function init(rb::IMAS.radial_build; layers...) rb.layer[k].identifier = UInt(hash(replace(replace(lowercase(rb.layer[k].name), "hfs" => ""), "lfs" => ""))) end if is_missing(rb.layer[end],:material) || rb.layer[end].material != "vacuum" - error("radial_build material of last layer ($(rb.layer[end].name)) must be `vacuum`") + error("Material of last layer ($(rb.layer[end].name)) must be `vacuum`") end return rb end """ - init(rb::IMAS.radial_build, eqt::IMAS.equilibrium; is_nuclear_facility=true) + init(rb::IMAS.build, eqt::IMAS.equilibrium; is_nuclear_facility=true) -Simple initialization of radial_build IDS based on equilibrium time_slice +Simple initialization of build IDS based on equilibrium time_slice """ -function init(rb::IMAS.radial_build, +function init(rb::IMAS.build, eq::IMAS.equilibrium; tf_shape_index::Int=3, is_nuclear_facility::Bool=true, @@ -141,22 +141,22 @@ function init(rb::IMAS.radial_build, rb.tf.coils_n = 16 # cross-section outlines - radial_build_cx(rb, eqt, tf_shape_index) + build_cx(rb, eqt, tf_shape_index) return rb end function wall_miller_conformal(rb, layer_type, elongation, triangularity; n_points=101) if layer_type == -1 - Rstart = IMAS.get_radial_build(rb, type=layer_type).start_radius - Rend = IMAS.get_radial_build(rb, type=layer_type).end_radius + Rstart = IMAS.get_build(rb, type=layer_type).start_radius + Rend = IMAS.get_build(rb, type=layer_type).end_radius line = miller_Rstart_Rend(Rstart, Rend, elongation, triangularity; n_points) return line, line else - Rstart_lfs = IMAS.get_radial_build(rb, type=layer_type, hfs=-1).start_radius - Rend_lfs = IMAS.get_radial_build(rb, type=layer_type, hfs=-1).end_radius - Rstart_hfs = IMAS.get_radial_build(rb, type=layer_type, hfs=1).start_radius - Rend_hfs = IMAS.get_radial_build(rb, type=layer_type, hfs=1).end_radius + Rstart_lfs = IMAS.get_build(rb, type=layer_type, hfs=-1).start_radius + Rend_lfs = IMAS.get_build(rb, type=layer_type, hfs=-1).end_radius + Rstart_hfs = IMAS.get_build(rb, type=layer_type, hfs=1).start_radius + Rend_hfs = IMAS.get_build(rb, type=layer_type, hfs=1).end_radius inner_line = miller_Rstart_Rend(Rend_hfs, Rstart_lfs, elongation, triangularity; n_points) outer_line = miller_Rstart_Rend(Rstart_hfs, Rend_lfs, elongation, triangularity; n_points) return inner_line, outer_line @@ -164,14 +164,14 @@ function wall_miller_conformal(rb, layer_type, elongation, triangularity; n_poin end """ - radial_build_cx(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice) -Translates 1D radial build to 2D cross-sections + build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice) +Translates 1D build to 2D cross-sections """ -function radial_build_cx(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice, tf_shape_index::Int) +function build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, tf_shape_index::Int) # Inner radii of the vacuum vessel - R_hfs_vessel = IMAS.get_radial_build(rb, type=-1).start_radius - R_lfs_vessel = IMAS.get_radial_build(rb, type=-1).end_radius + R_hfs_vessel = IMAS.get_build(rb, type=-1).start_radius + R_lfs_vessel = IMAS.get_build(rb, type=-1).end_radius # Vessel as buffered convex-hull polygon of LCFS and strike points r95, z95, _ = IMAS.flux_surface(eqt, (eqt.profiles_1d.psi[end] - eqt.profiles_1d.psi[1]) * 0.90 + eqt.profiles_1d.psi[1], true) @@ -220,8 +220,8 @@ function radial_build_cx(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slic end # vacuum vessel - IMAS.get_radial_build(rb, type=-1).outline.r = [v[1] for v in LibGEOS.coordinates(vessel_poly)[1]] - IMAS.get_radial_build(rb, type=-1).outline.z = [v[2] for v in LibGEOS.coordinates(vessel_poly)[1]] + IMAS.get_build(rb, type=-1).outline.r = [v[1] for v in LibGEOS.coordinates(vessel_poly)[1]] + IMAS.get_build(rb, type=-1).outline.z = [v[2] for v in LibGEOS.coordinates(vessel_poly)[1]] # all layers between vessel and OH vessel_to_oh = [] @@ -254,39 +254,39 @@ function radial_build_cx(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slic # plug L = 0 - R = IMAS.get_radial_build(rb, type=1).start_radius - D = minimum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) - U = maximum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) + R = IMAS.get_build(rb, type=1).start_radius + D = minimum(IMAS.get_build(rb, type=2, hfs=1).outline.z) + U = maximum(IMAS.get_build(rb, type=2, hfs=1).outline.z) rb.layer[1].outline.r, rb.layer[1].outline.z = rectangle_shape(L, R, D, U) # oh - L = IMAS.get_radial_build(rb, type=1).start_radius - R = IMAS.get_radial_build(rb, type=1).end_radius - D = minimum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) - U = maximum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) + L = IMAS.get_build(rb, type=1).start_radius + R = IMAS.get_build(rb, type=1).end_radius + D = minimum(IMAS.get_build(rb, type=2, hfs=1).outline.z) + U = maximum(IMAS.get_build(rb, type=2, hfs=1).outline.z) rb.layer[2].outline.r, rb.layer[2].outline.z = rectangle_shape(L, R, D, U) # cryostat L = 0 R = rb.layer[end].end_radius - D = minimum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) - rb.layer[end].thickness - U = maximum(IMAS.get_radial_build(rb, type=2, hfs=1).outline.z) + rb.layer[end].thickness + D = minimum(IMAS.get_build(rb, type=2, hfs=1).outline.z) - rb.layer[end].thickness + U = maximum(IMAS.get_build(rb, type=2, hfs=1).outline.z) + rb.layer[end].thickness rb.layer[end].outline.r, rb.layer[end].outline.z = rectangle_shape(L, R, D, U) # set the toroidal thickness of the TF coils based on the innermost radius and the number of coils - rb.tf.thickness = 2 * π * IMAS.get_radial_build(rb, type=2, hfs=1).start_radius / rb.tf.coils_n + rb.tf.thickness = 2 * π * IMAS.get_build(rb, type=2, hfs=1).start_radius / rb.tf.coils_n return rb end -function optimize_shape(rb::IMAS.radial_build, layer_index::Int, tf_shape_index::Int) +function optimize_shape(rb::IMAS.build, layer_index::Int, tf_shape_index::Int) # properties of current layer layer = rb.layer[layer_index] id = rb.layer[layer_index].identifier r_start = layer.start_radius - r_end = IMAS.get_radial_build(rb, identifier=layer.identifier, hfs=-1).end_radius + r_end = IMAS.get_build(rb, identifier=layer.identifier, hfs=-1).end_radius hfs_thickness = layer.thickness - lfs_thickness = IMAS.get_radial_build(rb, identifier=id, hfs=-1).thickness + lfs_thickness = IMAS.get_build(rb, identifier=id, hfs=-1).thickness target_minimum_distance = (hfs_thickness + lfs_thickness) / 2.0 # obstruction @@ -336,16 +336,16 @@ end #= ================ =# mutable struct FluxSwingActor <: AbstractActor - rb::IMAS.radial_build + rb::IMAS.build eqt::IMAS.equilibrium__time_slice cp::IMAS.core_profiles end function FluxSwingActor(dd::IMAS.dd) - return FluxSwingActor(dd.radial_build, dd.equilibrium, dd.core_profiles) + return FluxSwingActor(dd.build, dd.equilibrium, dd.core_profiles) end -function FluxSwingActor(rb::IMAS.radial_build, eq::IMAS.equilibrium, cp::IMAS.core_profiles) +function FluxSwingActor(rb::IMAS.build, eq::IMAS.equilibrium, cp::IMAS.core_profiles) return FluxSwingActor(rb, eq.time_slice[], cp) end @@ -357,7 +357,7 @@ function step(flxactor::FluxSwingActor) end """ - rampup_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) + rampup_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) Estimate OH flux requirement during rampup @@ -366,7 +366,7 @@ NOTES: * eqt is supposed to be the equilibrium right at the end of the rampup phase, beginning of flattop * core_profiles is only used to get core_profiles.global_quantities.ejima """ -function rampup_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) +function rampup_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) # from IMAS dd to local variables majorRadius = eqt.boundary.geometric_axis.r minorRadius = eqt.boundary.minor_radius @@ -389,14 +389,14 @@ function rampup_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__ end """ - flattop_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) + flattop_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) Estimate OH flux requirement during flattop NOTES: * this is a dummy function right now!, we simply take 1/2 of the rampup """ -function flattop_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) +function flattop_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, cp::IMAS.core_profiles) # from IMAS dd to local variables # ============================= # @@ -410,7 +410,7 @@ function flattop_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium_ end """ - pf_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice) + pf_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice) Estimate vertical field from PF coils and its contribution to flux swing @@ -418,7 +418,7 @@ NOTES: * Equations from GASC (Stambaugh FST 2011) * eqt is supposed to be the equilibrium right at the end of the rampup phase, beginning of flattop """ -function pf_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time_slice) +function pf_flux_requirements(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice) # from IMAS dd to local variables majorRadius = eqt.boundary.geometric_axis.r minorRadius = eqt.boundary.minor_radius @@ -437,7 +437,7 @@ function pf_flux_requirements(rb::IMAS.radial_build, eqt::IMAS.equilibrium__time end """ - oh_requirements(rb::IMAS.radial_build, double_swing::Bool=true) + oh_requirements(rb::IMAS.build, double_swing::Bool=true) Evaluate OH current density and B_field required for rampup and flattop @@ -445,8 +445,8 @@ NOTES: * Equations from GASC (Stambaugh FST 2011) * Also relevant: `Engineering design solutions of flux swing with structural requirements for ohmic heating solenoids` Smith, R. A. September 30, 1977 """ -function oh_requirements(rb::IMAS.radial_build, double_swing::Bool=true) - innerSolenoidRadius, outerSolenoidRadius = (IMAS.get_radial_build(rb, type=1).start_radius, IMAS.get_radial_build(rb, type=1).end_radius) +function oh_requirements(rb::IMAS.build, double_swing::Bool=true) + innerSolenoidRadius, outerSolenoidRadius = (IMAS.get_build(rb, type=1).start_radius, IMAS.get_build(rb, type=1).end_radius) totalOhFluxReq = rb.flux_swing_requirements.rampup.total + rb.flux_swing_requirements.flattop + rb.flux_swing_requirements.pf # ============================= # @@ -469,14 +469,14 @@ end function stress_calculations(dd::IMAS.dd) error("not completed yet") - rb = dd.radial_build - B0_TF = dd.radial_build.tf_b_field_max - R0_TF = sum((IMAS.get_radial_build(rb, type=-1).start_radius, IMAS.get_radial_build(rb, type=-1).end_radius)) / 2.0 - Rtf1 = IMAS.get_radial_build(rb, type=2).start_radius - Rtf2 = IMAS.get_radial_build(rb, type=2).end_radius - B0_OH = dd.radial_build.oh_b_field_max - R_sol1 = IMAS.get_radial_build(rb, type=1).start_radius - R_sol2 = IMAS.get_radial_build(rb, type=1).end_radius + rb = dd.build + B0_TF = dd.build.tf_b_field_max + R0_TF = sum((IMAS.get_build(rb, type=-1).start_radius, IMAS.get_build(rb, type=-1).end_radius)) / 2.0 + Rtf1 = IMAS.get_build(rb, type=2).start_radius + Rtf2 = IMAS.get_build(rb, type=2).end_radius + B0_OH = dd.build.oh_b_field_max + R_sol1 = IMAS.get_build(rb, type=1).start_radius + R_sol2 = IMAS.get_build(rb, type=1).end_radius s_ax_ave = something f_t_ss_tot_in = something f_oh_cu_in = something diff --git a/src/actors/coils_actor.jl b/src/actors/coils_actor.jl index f32c87f91..8592ac222 100644 --- a/src/actors/coils_actor.jl +++ b/src/actors/coils_actor.jl @@ -25,9 +25,9 @@ function finite_size_OH_coils(z, coils_cleareance) end """ - init(pf_active::IMAS.pf_active, rb::IMAS.radial_build, n_coils::Vector) + init(pf_active::IMAS.pf_active, rb::IMAS.build, n_coils::Vector) -Use radial build layers outline to initialize PF coils distribution +Use build layers outline to initialize PF coils distribution Attributes * n_coils: number of pf coils per coil-placement rail (the first one is the OH, and then one for each vacuum region) @@ -36,13 +36,13 @@ Attributes * coils_elements_area: Cross-sectional area taken up by individual filaments in a coil (per rail) """ function init(pf_active::IMAS.pf_active, - rb::IMAS.radial_build, + rb::IMAS.build, n_coils::Vector{TI} where TI <: Int; pf_coils_size::Union{Nothing, Real, Vector{TR}} where TR <: Real=nothing, coils_cleareance::Union{Nothing, Real, Vector{TR}} where TR <: Real=nothing, coils_elements_area::Union{Nothing, Real, Vector{TR}} where TR <: Real=nothing) - OH_layer = IMAS.get_radial_build(rb, type=1) + OH_layer = IMAS.get_build(rb, type=1) empty!(pf_active) resize!(rb.pf_coils_rail, length(n_coils)) @@ -108,7 +108,7 @@ function init(pf_active::IMAS.pf_active, krail += 1 nc = n_coils[krail] - # add rail info to radial_build IDS + # add rail info to build IDS rb.pf_coils_rail[krail].name = replace(replace(layer.name, "hfs " => ""), "lfs " => "") rb.pf_coils_rail[krail].coils_number = nc rb.pf_coils_rail[krail].coils_elements_area = coils_elements_area[krail] @@ -116,11 +116,11 @@ function init(pf_active::IMAS.pf_active, # pick layers with outline information if layer.hfs == 1 - outer_layer = IMAS.get_radial_build(rb, identifier=rb.layer[k].identifier, hfs=1) - inner_layer = IMAS.get_radial_build(rb, identifier=rb.layer[k + 1].identifier, hfs=[1,0]) + outer_layer = IMAS.get_build(rb, identifier=rb.layer[k].identifier, hfs=1) + inner_layer = IMAS.get_build(rb, identifier=rb.layer[k + 1].identifier, hfs=[1,0]) else - inner_layer = IMAS.get_radial_build(rb, identifier=rb.layer[k - 1].identifier, hfs=1) - outer_layer = IMAS.get_radial_build(rb, identifier=rb.layer[k].identifier, hfs=[1,0]) + inner_layer = IMAS.get_build(rb, identifier=rb.layer[k - 1].identifier, hfs=1) + outer_layer = IMAS.get_build(rb, identifier=rb.layer[k].identifier, hfs=[1,0]) end # generate rail between the two layers where coils will be placed and will be able to slide during the `optimization` phase @@ -167,7 +167,7 @@ function init(pf_active::IMAS.pf_active, distance = (distance .- distance[1]) distance = (distance ./ distance[end]).*2.0.-1.0 - # add rail info to radial_build IDS + # add rail info to build IDS rb.pf_coils_rail[krail].outline.r = valid_r rb.pf_coils_rail[krail].outline.z = valid_z rb.pf_coils_rail[krail].outline.distance = distance @@ -218,7 +218,7 @@ mutable struct PFcoilsOptActor <: AbstractActor eq_out::IMAS.equilibrium time::Real pf_active::IMAS.pf_active - radial_build::IMAS.radial_build + rb::IMAS.build symmetric::Bool λ_regularize::Real trace::PFcoilsOptTrace @@ -226,7 +226,7 @@ mutable struct PFcoilsOptActor <: AbstractActor end function PFcoilsOptActor(eq_in::IMAS.equilibrium, - rb::IMAS.radial_build, + rb::IMAS.build, pf::IMAS.pf_active, n_coils::Vector; λ_regularize=1E-13, @@ -372,7 +372,7 @@ function AD_GS.Green(coil::GS_IMAS_pf_active__coil, R::Real, Z::Real) end # step -function pack_rail(rb::IMAS.radial_build, λ_regularize::Float64, symmetric::Bool)::Vector{Float64} +function pack_rail(rb::IMAS.build, λ_regularize::Float64, symmetric::Bool)::Vector{Float64} distances = [] for rail in rb.pf_coils_rail # not symmetric @@ -391,7 +391,7 @@ function pack_rail(rb::IMAS.radial_build, λ_regularize::Float64, symmetric::Boo return packed end -function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, rb::IMAS.radial_build) +function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, rb::IMAS.build) distances = packed[1:end - 1] λ_regularize = packed[end] @@ -448,7 +448,7 @@ function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, rb:: return 10^λ_regularize end -function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_coils::Vector, fixed_coils::Vector, symmetric::Bool, λ_regularize::Real, λ_ψ::Real, λ_null::Real, λ_currents::Real, rb::IMAS.radial_build, maxiter::Int, verbose::Bool) +function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_coils::Vector, fixed_coils::Vector, symmetric::Bool, λ_regularize::Real, λ_ψ::Real, λ_null::Real, λ_currents::Real, rb::IMAS.build, maxiter::Int, verbose::Bool) fixed_eqs = [] weights = [] @@ -468,7 +468,7 @@ function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_c fixed_eq = IMAS2Equilibrium(eqt) # private flux regions private = IMAS.flux_surface(eqt,eqt.profiles_1d.psi[end],false) - vessel = IMAS.get_radial_build(rb, type=-1, hfs=0) + vessel = IMAS.get_build(rb, type=-1, hfs=0) Rx = [] Zx = [] for (pr, pz) in private @@ -589,7 +589,7 @@ function step(pfactor::PFcoilsOptActor; coil.time = pfactor.eq_in.time end - rb = pfactor.radial_build + rb = pfactor.rb # run rail type optimizer if optimization_scheme in [:rail, :static] (λ_regularize, trace) = optimize_coils_rail(pfactor.eq_in; pinned_coils, optim_coils, fixed_coils, symmetric, λ_regularize, λ_ψ, λ_null, λ_currents, rb, maxiter, verbose) @@ -632,7 +632,7 @@ end Plot PFcoilsOptActor optimization cross-section """ -@recipe function plot_pfcoilsactor_cx(pfactor::PFcoilsOptActor; time_index=1, equilibrium=true, radial_build=true, coils_flux=false, rail=false, plot_r_buffer=1.6) +@recipe function plot_pfcoilsactor_cx(pfactor::PFcoilsOptActor; time_index=1, equilibrium=true, build=true, coils_flux=false, rail=false, plot_r_buffer=1.6) # if there is no equilibrium then treat this as a field_null plot field_null = false @@ -641,23 +641,23 @@ Plot PFcoilsOptActor optimization cross-section field_null = true end - # when plotting coils_flux the radial_build is not visible anyways + # when plotting coils_flux the build is not visible anyways if coils_flux - radial_build = false + build = false end # setup plotting area - xlim = [0.0, maximum(pfactor.radial_build.layer[end].outline.r)] - ylim = [minimum(pfactor.radial_build.layer[end].outline.z), maximum(pfactor.radial_build.layer[end].outline.z)] + xlim = [0.0, maximum(pfactor.rb.layer[end].outline.r)] + ylim = [minimum(pfactor.rb.layer[end].outline.z), maximum(pfactor.rb.layer[end].outline.z)] xlim --> xlim * plot_r_buffer ylim --> ylim aspect_ratio --> :equal - # plot radial build - if radial_build + # plot build + if build @series begin exclude_layers --> [:oh] - pfactor.radial_build + pfactor.rb end end @@ -708,7 +708,7 @@ Plot PFcoilsOptActor optimization cross-section @series begin outlines --> true exclude_layers --> [:oh] - pfactor.radial_build + pfactor.rb end end @@ -744,10 +744,10 @@ Plot PFcoilsOptActor optimization cross-section # plot optimization rails if rail - for (krail, rail) in enumerate(pfactor.radial_build.pf_coils_rail) + for (krail, rail) in enumerate(pfactor.rb.pf_coils_rail) if ! is_missing(rail.outline,:r) @series begin - label --> (radial_build ? "Coil opt. rail" : "") + label --> (build ? "Coil opt. rail" : "") primary --> krail == 1 ? true : false color --> :gray linestyle --> :dash From 28a326011fa66a1e9ec5ebb380c11843af0424b2 Mon Sep 17 00:00:00 2001 From: Orso Meneghini Date: Fri, 28 Jan 2022 00:32:33 -0800 Subject: [PATCH 2/2] rb --> bd --- examples/radial_build.ipynb | 3727 ++--------------------------------- src/actors/build_actor.jl | 210 +- src/actors/coils_actor.jl | 98 +- 3 files changed, 337 insertions(+), 3698 deletions(-) diff --git a/examples/radial_build.ipynb b/examples/radial_build.ipynb index b569981d4..bb7775355 100644 --- a/examples/radial_build.ipynb +++ b/examples/radial_build.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "id": "252534d3-5de2-43eb-a2eb-62976591e8f2", "metadata": {}, "outputs": [ @@ -34,93 +34,93 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", "\n" ] }, @@ -546,12 +546,33 @@ " Iterations: 36\n", " f(x) calls: 70\n", "\n", - " 7.352394 seconds (59.75 M allocations: 1.622 GiB, 3.29% gc time, 64.37% compilation time)\n", + " 2.555740 seconds (42.48 M allocations: 672.371 MiB, 2.22% gc time)\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_tor = 0.018538831972279315\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_pol = 1.026350289869195\n", "(dd.equilibrium.time_slice[]).global_quantities.beta_normal = 1.8758347713832044\n", "(dd.equilibrium.time_slice[]).global_quantities.ip = 1.5588225003711341e7\n" ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "┌ Error: Failed to revise /Users/meneghini/Coding/julia/FUSE/src/actors/coils_actor.jl\n", + "│ exception = Revise.ReviseEvalException(\"/Users/meneghini/Coding/julia/FUSE/src/actors/coils_actor.jl:216\", ErrorException(\"invalid redefinition of constant PFcoilsOptActor\"), Any[(top-level scope at coils_actor.jl:216, 1)])\n", + "└ @ Revise /Users/meneghini/.julia/packages/Revise/jHTGK/src/packagedef.jl:708\n", + "┌ Error: Failed to revise /Users/meneghini/Coding/julia/FUSE/src/actors/build_actor.jl\n", + "│ exception = Revise.ReviseEvalException(\"/Users/meneghini/Coding/julia/FUSE/src/actors/build_actor.jl:338\", ErrorException(\"invalid redefinition of constant FluxSwingActor\"), Any[(top-level scope at build_actor.jl:338, 1)])\n", + "└ @ Revise /Users/meneghini/.julia/packages/Revise/jHTGK/src/packagedef.jl:708\n", + "┌ Warning: The running code does not match the saved version for the following files:\n", + "│ \n", + "│ /Users/meneghini/Coding/julia/FUSE/src/actors/coils_actor.jl\n", + "│ /Users/meneghini/Coding/julia/FUSE/src/actors/build_actor.jl\n", + "│ \n", + "│ If the error was due to evaluation order, it can sometimes be resolved by calling `Revise.retry()`.\n", + "│ Use Revise.errors() to report errors again. Only the first error in each file is shown.\n", + "│ Your prompt color may be yellow until the errors are resolved.\n", + "└ @ Revise /Users/meneghini/.julia/packages/Revise/jHTGK/src/packagedef.jl:818\n" + ] } ], "source": [ @@ -601,7 +622,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "id": "aff8c803-64d8-460d-b0d0-98f08d6bf661", "metadata": {}, "outputs": [ @@ -611,87 +632,87 @@ "\n", "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", "\n", - " \n", + " \n", " \n", " \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "\n", + "\n", + "\n", + "\n", - "\n", - "\n", - "\n", - "\n" + "\n" ] }, - "execution_count": 4, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -1668,3402 +1689,36 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "id": "56f20782-3539-4022-bc36-b0b41c3d4d9c", "metadata": {}, "outputs": [ { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" + "ename": "LoadError", + "evalue": "MethodError: no method matching FluxSwingActor(::IMAS.build, ::IMAS.equilibrium, ::IMAS.core_profiles)", + "output_type": "error", + "traceback": [ + "MethodError: no method matching FluxSwingActor(::IMAS.build, ::IMAS.equilibrium, ::IMAS.core_profiles)", + "", + "Stacktrace:", + " [1] FluxSwingActor(dd::IMAS.dd)", + " @ FUSE ~/Coding/julia/FUSE/src/actors/build_actor.jl:345", + " [2] top-level scope", + " @ In[10]:10", + " [3] eval", + " @ ./boot.jl:373 [inlined]", + " [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)", + " @ Base ./loading.jl:1196" + ] } ], "source": [ "# initialize radial build IDS\n", "eq = dd.equilibrium\n", "cp = dd.core_profiles\n", - "rb = dd.build\n", + "bd = dd.build\n", "\n", - "FUSE.init(rb, eq, tf_shape_index=3, is_nuclear_facility=true, pf_inside_tf=false, pf_outside_tf=true);\n", + "FUSE.init(bd, eq, tf_shape_index=3, is_nuclear_facility=true, pf_inside_tf=false, pf_outside_tf=true);\n", "FUSE.init(cp, ejima=0.4);\n", "\n", "# run FluxSwingActor\n", @@ -5072,46 +1727,30 @@ "FUSE.finalize(ohactor)\n", "\n", "plot(eq,color=:gray)\n", - "plot!(rb,outline=true)\n", - "display(plot!(rb,cx=false))" + "plot!(bd,outline=true)\n", + "display(plot!(bd,cx=false))" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 11, "id": "21d8b059-1b9c-4cde-afca-a5b67a1cb99e", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300441394294\n", - "0.05925300564940361\n", - "0.05925300564940361\n", - "0.05925300441394294\n", - " * Status: success\n", - "\n", - " * Candidate solution\n", - " Final objective value: 5.925300e-02\n", - "\n", - " * Found with\n", - " Algorithm: Nelder-Mead\n", - "\n", - " * Convergence measures\n", - " √(Σ(yᵢ-ȳ)²)/n ≤ 1.0e-08\n", - "\n", - " * Work counters\n", - " Seconds run: 0 (vs limit 120)\n", - " Iterations: 0\n", - " f(x) calls: 9\n", - "\n" + "ename": "LoadError", + "evalue": "MethodError: no method matching PFcoilsOptActor(::IMAS.equilibrium, ::IMAS.build, ::IMAS.pf_active, ::Vector{Int64}; coil_model=:simple)", + "output_type": "error", + "traceback": [ + "MethodError: no method matching PFcoilsOptActor(::IMAS.equilibrium, ::IMAS.build, ::IMAS.pf_active, ::Vector{Int64}; coil_model=:simple)", + "", + "Stacktrace:", + " [1] top-level scope", + " @ In[11]:2", + " [2] eval", + " @ ./boot.jl:373 [inlined]", + " [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)", + " @ Base ./loading.jl:1196" ] } ], @@ -23807,7 +20446,7 @@ "display(plot(pfoptactor.pf_active,:currents, time_index=2))\n", "display(plot(pfoptactor,equilibrium=true,time_index=2,plot_r_buffer=1.0))\n", "\n", - "#IMAS.imas2json(rb,\"radial_build_4.json\")" + "#IMAS.imas2json(bd,\"radial_build_4.json\")" ] }, { @@ -27440,7 +24079,7 @@ "dd.equilibrium=pfoptactor.eq_out\n", "eq=dd.equilibrium\n", "\n", - "FUSE.init(rb, eq, tf_shape_index=3, is_nuclear_facility=true, pf_inside_tf=false, pf_outside_tf=true);\n", + "FUSE.init(bd, eq, tf_shape_index=3, is_nuclear_facility=true, pf_inside_tf=false, pf_outside_tf=true);\n", "FUSE.init(cp, ejima=0.4);\n", "\n", "# run FluxSwingActor\n", @@ -27449,8 +24088,8 @@ "FUSE.finalize(ohactor)\n", "\n", "plot(eq,color=:gray)\n", - "plot!(rb,outline=true)\n", - "display(plot!(rb,cx=false))" + "plot!(bd,outline=true)\n", + "display(plot!(bd,cx=false))" ] }, { diff --git a/src/actors/build_actor.jl b/src/actors/build_actor.jl index 79d711e2a..bff0f21d4 100644 --- a/src/actors/build_actor.jl +++ b/src/actors/build_actor.jl @@ -17,7 +17,7 @@ end # init build # #= ========== =# """ - init(rb::IMAS.build; layers...) + init(bd::IMAS.build; layers...) Initialize build IDS based on center stack layers (thicknesses) @@ -34,59 +34,59 @@ layer[:].hfs is set depending on if "hfs" or "lfs" appear in the name layer[:].identifier is created as a hash of then name removing "hfs" or "lfs" """ -function init(rb::IMAS.build; layers...) +function init(bd::IMAS.build; layers...) # empty build IDS - empty!(rb) + empty!(bd) # assign layers - resize!(rb.layer, length([layer_name for (layer_name, layer_thickness) in layers if layer_thickness >= 0.0])) + resize!(bd.layer, length([layer_name for (layer_name, layer_thickness) in layers if layer_thickness >= 0.0])) k = 0 for (layer_name, layer_thickness) in layers if layer_thickness < 0.0 continue end k += 1 - rb.layer[k].thickness = layer_thickness - rb.layer[k].name = replace(String(layer_name), "_" => " ") - if occursin("gap", lowercase(rb.layer[k].name)) - rb.layer[k].type = 0 - rb.layer[k].material = "vacuum" - elseif uppercase(rb.layer[k].name) == "OH" - rb.layer[k].type = 1 - elseif occursin("TF", uppercase(rb.layer[k].name)) - rb.layer[k].type = 2 - elseif occursin("shield", lowercase(rb.layer[k].name)) - rb.layer[k].type = 3 - elseif occursin("blanket", lowercase(rb.layer[k].name)) - rb.layer[k].type = 4 - elseif occursin("wall", lowercase(rb.layer[k].name)) - rb.layer[k].type = 5 + bd.layer[k].thickness = layer_thickness + bd.layer[k].name = replace(String(layer_name), "_" => " ") + if occursin("gap", lowercase(bd.layer[k].name)) + bd.layer[k].type = 0 + bd.layer[k].material = "vacuum" + elseif uppercase(bd.layer[k].name) == "OH" + bd.layer[k].type = 1 + elseif occursin("TF", uppercase(bd.layer[k].name)) + bd.layer[k].type = 2 + elseif occursin("shield", lowercase(bd.layer[k].name)) + bd.layer[k].type = 3 + elseif occursin("blanket", lowercase(bd.layer[k].name)) + bd.layer[k].type = 4 + elseif occursin("wall", lowercase(bd.layer[k].name)) + bd.layer[k].type = 5 end - if occursin("hfs", lowercase(rb.layer[k].name)) - rb.layer[k].hfs = 1 - elseif occursin("lfs", lowercase(rb.layer[k].name)) - rb.layer[k].hfs = -1 + if occursin("hfs", lowercase(bd.layer[k].name)) + bd.layer[k].hfs = 1 + elseif occursin("lfs", lowercase(bd.layer[k].name)) + bd.layer[k].hfs = -1 else - rb.layer[k].hfs = 0 + bd.layer[k].hfs = 0 end - if occursin("vessel", lowercase(rb.layer[k].name)) - rb.layer[k].type = -1 - rb.layer[k].material = "vacuum" + if occursin("vessel", lowercase(bd.layer[k].name)) + bd.layer[k].type = -1 + bd.layer[k].material = "vacuum" end - rb.layer[k].identifier = UInt(hash(replace(replace(lowercase(rb.layer[k].name), "hfs" => ""), "lfs" => ""))) + bd.layer[k].identifier = UInt(hash(replace(replace(lowercase(bd.layer[k].name), "hfs" => ""), "lfs" => ""))) end - if is_missing(rb.layer[end],:material) || rb.layer[end].material != "vacuum" - error("Material of last layer ($(rb.layer[end].name)) must be `vacuum`") + if is_missing(bd.layer[end],:material) || bd.layer[end].material != "vacuum" + error("Material of last layer ($(bd.layer[end].name)) must be `vacuum`") end - return rb + return bd end """ - init(rb::IMAS.build, eqt::IMAS.equilibrium; is_nuclear_facility=true) + init(bd::IMAS.build, eqt::IMAS.equilibrium; is_nuclear_facility=true) Simple initialization of build IDS based on equilibrium time_slice """ -function init(rb::IMAS.build, +function init(bd::IMAS.build, eq::IMAS.equilibrium; tf_shape_index::Int=3, is_nuclear_facility::Bool=true, @@ -102,7 +102,7 @@ function init(rb::IMAS.build, rmin -= gap rmax += gap dr = rmin / n_hfs_layers - init(rb, + init(bd, gap_OH=dr * 2.0, OH=dr, hfs_TF=dr, @@ -124,7 +124,7 @@ function init(rb::IMAS.build, rmin -= gap rmax += gap dr = rmin / n_hfs_layers - init(rb, + init(bd, gap_OH=dr * 2.0, OH=dr, hfs_TF=dr, @@ -138,25 +138,25 @@ function init(rb::IMAS.build, end # TF coils - rb.tf.coils_n = 16 + bd.tf.coils_n = 16 # cross-section outlines - build_cx(rb, eqt, tf_shape_index) + build_cx(bd, eqt, tf_shape_index) - return rb + return bd end -function wall_miller_conformal(rb, layer_type, elongation, triangularity; n_points=101) +function wall_miller_conformal(bd, layer_type, elongation, triangularity; n_points=101) if layer_type == -1 - Rstart = IMAS.get_build(rb, type=layer_type).start_radius - Rend = IMAS.get_build(rb, type=layer_type).end_radius + Rstart = IMAS.get_build(bd, type=layer_type).start_radius + Rend = IMAS.get_build(bd, type=layer_type).end_radius line = miller_Rstart_Rend(Rstart, Rend, elongation, triangularity; n_points) return line, line else - Rstart_lfs = IMAS.get_build(rb, type=layer_type, hfs=-1).start_radius - Rend_lfs = IMAS.get_build(rb, type=layer_type, hfs=-1).end_radius - Rstart_hfs = IMAS.get_build(rb, type=layer_type, hfs=1).start_radius - Rend_hfs = IMAS.get_build(rb, type=layer_type, hfs=1).end_radius + Rstart_lfs = IMAS.get_build(bd, type=layer_type, hfs=-1).start_radius + Rend_lfs = IMAS.get_build(bd, type=layer_type, hfs=-1).end_radius + Rstart_hfs = IMAS.get_build(bd, type=layer_type, hfs=1).start_radius + Rend_hfs = IMAS.get_build(bd, type=layer_type, hfs=1).end_radius inner_line = miller_Rstart_Rend(Rend_hfs, Rstart_lfs, elongation, triangularity; n_points) outer_line = miller_Rstart_Rend(Rstart_hfs, Rend_lfs, elongation, triangularity; n_points) return inner_line, outer_line @@ -164,14 +164,14 @@ function wall_miller_conformal(rb, layer_type, elongation, triangularity; n_poin end """ - build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice) + build_cx(bd::IMAS.build, eqt::IMAS.equilibrium__time_slice) Translates 1D build to 2D cross-sections """ -function build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, tf_shape_index::Int) +function build_cx(bd::IMAS.build, eqt::IMAS.equilibrium__time_slice, tf_shape_index::Int) # Inner radii of the vacuum vessel - R_hfs_vessel = IMAS.get_build(rb, type=-1).start_radius - R_lfs_vessel = IMAS.get_build(rb, type=-1).end_radius + R_hfs_vessel = IMAS.get_build(bd, type=-1).start_radius + R_lfs_vessel = IMAS.get_build(bd, type=-1).end_radius # Vessel as buffered convex-hull polygon of LCFS and strike points r95, z95, _ = IMAS.flux_surface(eqt, (eqt.profiles_1d.psi[end] - eqt.profiles_1d.psi[1]) * 0.90 + eqt.profiles_1d.psi[1], true) @@ -220,13 +220,13 @@ function build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, tf_shape_in end # vacuum vessel - IMAS.get_build(rb, type=-1).outline.r = [v[1] for v in LibGEOS.coordinates(vessel_poly)[1]] - IMAS.get_build(rb, type=-1).outline.z = [v[2] for v in LibGEOS.coordinates(vessel_poly)[1]] + IMAS.get_build(bd, type=-1).outline.r = [v[1] for v in LibGEOS.coordinates(vessel_poly)[1]] + IMAS.get_build(bd, type=-1).outline.z = [v[2] for v in LibGEOS.coordinates(vessel_poly)[1]] # all layers between vessel and OH vessel_to_oh = [] valid = false - for (k, layer) in reverse(collect(enumerate(rb.layer))) + for (k, layer) in reverse(collect(enumerate(bd.layer))) # stop once you see the OH if layer.type == 1 valid = false @@ -243,55 +243,55 @@ function build_cx(rb::IMAS.build, eqt::IMAS.equilibrium__time_slice, tf_shape_in shape_set = false for (n, k) in enumerate(vessel_to_oh) # layer that preceeds the TF (or shield) sets the TF (and shield) shape - if (!shape_set) && (n ""), "lfs " => "") - rb.pf_coils_rail[krail].coils_number = nc - rb.pf_coils_rail[krail].coils_elements_area = coils_elements_area[krail] - rb.pf_coils_rail[krail].coils_cleareance = coils_cleareance[krail] + bd.pf_coils_rail[krail].name = replace(replace(layer.name, "hfs " => ""), "lfs " => "") + bd.pf_coils_rail[krail].coils_number = nc + bd.pf_coils_rail[krail].coils_elements_area = coils_elements_area[krail] + bd.pf_coils_rail[krail].coils_cleareance = coils_cleareance[krail] # pick layers with outline information if layer.hfs == 1 - outer_layer = IMAS.get_build(rb, identifier=rb.layer[k].identifier, hfs=1) - inner_layer = IMAS.get_build(rb, identifier=rb.layer[k + 1].identifier, hfs=[1,0]) + outer_layer = IMAS.get_build(bd, identifier=bd.layer[k].identifier, hfs=1) + inner_layer = IMAS.get_build(bd, identifier=bd.layer[k + 1].identifier, hfs=[1,0]) else - inner_layer = IMAS.get_build(rb, identifier=rb.layer[k - 1].identifier, hfs=1) - outer_layer = IMAS.get_build(rb, identifier=rb.layer[k].identifier, hfs=[1,0]) + inner_layer = IMAS.get_build(bd, identifier=bd.layer[k - 1].identifier, hfs=1) + outer_layer = IMAS.get_build(bd, identifier=bd.layer[k].identifier, hfs=[1,0]) end # generate rail between the two layers where coils will be placed and will be able to slide during the `optimization` phase @@ -143,9 +143,9 @@ function init(pf_active::IMAS.pf_active, end end if length(valid_k) == 0 - rb.pf_coils_rail[krail].outline.r = Real[] - rb.pf_coils_rail[krail].outline.z = Real[] - rb.pf_coils_rail[krail].outline.distance = Real[] + bd.pf_coils_rail[krail].outline.r = Real[] + bd.pf_coils_rail[krail].outline.z = Real[] + bd.pf_coils_rail[krail].outline.distance = Real[] error("Coils on PF rail #$(krail-1) are too big to fit.") continue end @@ -168,9 +168,9 @@ function init(pf_active::IMAS.pf_active, distance = (distance ./ distance[end]).*2.0.-1.0 # add rail info to build IDS - rb.pf_coils_rail[krail].outline.r = valid_r - rb.pf_coils_rail[krail].outline.z = valid_z - rb.pf_coils_rail[krail].outline.distance = distance + bd.pf_coils_rail[krail].outline.r = valid_r + bd.pf_coils_rail[krail].outline.z = valid_z + bd.pf_coils_rail[krail].outline.distance = distance if nc == 0 continue @@ -218,7 +218,7 @@ mutable struct PFcoilsOptActor <: AbstractActor eq_out::IMAS.equilibrium time::Real pf_active::IMAS.pf_active - rb::IMAS.build + bd::IMAS.build symmetric::Bool λ_regularize::Real trace::PFcoilsOptTrace @@ -226,13 +226,13 @@ mutable struct PFcoilsOptActor <: AbstractActor end function PFcoilsOptActor(eq_in::IMAS.equilibrium, - rb::IMAS.build, + bd::IMAS.build, pf::IMAS.pf_active, n_coils::Vector; λ_regularize=1E-13, coil_model=:simple) # initialize coils location - init(pf, rb, n_coils) + init(pf, bd, n_coils) # basic constructors eq_out = deepcopy(eq_in) @@ -241,7 +241,7 @@ function PFcoilsOptActor(eq_in::IMAS.equilibrium, time = eq_in.time[time_index] # constructor - pfactor = PFcoilsOptActor(eq_in, eq_out, time, pf, rb, symmetric, λ_regularize, PFcoilsOptTrace(), coil_model) + pfactor = PFcoilsOptActor(eq_in, eq_out, time, pf, bd, symmetric, λ_regularize, PFcoilsOptTrace(), coil_model) return pfactor end @@ -372,9 +372,9 @@ function AD_GS.Green(coil::GS_IMAS_pf_active__coil, R::Real, Z::Real) end # step -function pack_rail(rb::IMAS.build, λ_regularize::Float64, symmetric::Bool)::Vector{Float64} +function pack_rail(bd::IMAS.build, λ_regularize::Float64, symmetric::Bool)::Vector{Float64} distances = [] - for rail in rb.pf_coils_rail + for rail in bd.pf_coils_rail # not symmetric if ! symmetric coil_distances = collect(range(-1.0, 1.0, length=rail.coils_number + 2))[2:end - 1] @@ -391,14 +391,14 @@ function pack_rail(rb::IMAS.build, λ_regularize::Float64, symmetric::Bool)::Vec return packed end -function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, rb::IMAS.build) +function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, bd::IMAS.build) distances = packed[1:end - 1] λ_regularize = packed[end] if length(optim_coils) != 0 # optim_coils have zero length in case of the `static` optimization kcoil = 0 koptim = 0 - for rail in rb.pf_coils_rail + for rail in bd.pf_coils_rail r_interp = IMAS.interp(rail.outline.distance, rail.outline.r, extrapolation_bc=:flat) z_interp = IMAS.interp(rail.outline.distance, rail.outline.z, extrapolation_bc=:flat) # not symmetric @@ -448,7 +448,7 @@ function unpack_rail!(optim_coils::Vector, packed::Vector, symmetric::Bool, rb:: return 10^λ_regularize end -function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_coils::Vector, fixed_coils::Vector, symmetric::Bool, λ_regularize::Real, λ_ψ::Real, λ_null::Real, λ_currents::Real, rb::IMAS.build, maxiter::Int, verbose::Bool) +function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_coils::Vector, fixed_coils::Vector, symmetric::Bool, λ_regularize::Real, λ_ψ::Real, λ_null::Real, λ_currents::Real, bd::IMAS.build, maxiter::Int, verbose::Bool) fixed_eqs = [] weights = [] @@ -468,7 +468,7 @@ function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_c fixed_eq = IMAS2Equilibrium(eqt) # private flux regions private = IMAS.flux_surface(eqt,eqt.profiles_1d.psi[end],false) - vessel = IMAS.get_build(rb, type=-1, hfs=0) + vessel = IMAS.get_build(bd, type=-1, hfs=0) Rx = [] Zx = [] for (pr, pz) in private @@ -486,14 +486,14 @@ function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_c end end - packed = pack_rail(rb, λ_regularize, symmetric) + packed = pack_rail(bd, λ_regularize, symmetric) trace = PFcoilsOptTrace() packed_tmp = [] function placement_cost(packed; do_trace=false) try push!(packed_tmp, packed) - λ_regularize = unpack_rail!(optim_coils, packed, symmetric, rb) + λ_regularize = unpack_rail!(optim_coils, packed, symmetric, bd) coils = vcat(pinned_coils, optim_coils) all_cost_ψ = [] all_cost_currents = [] @@ -534,13 +534,13 @@ function optimize_coils_rail(eq::IMAS.equilibrium; pinned_coils::Vector, optim_c if maxiter == 0 placement_cost(packed) - λ_regularize = unpack_rail!(optim_coils, packed, symmetric, rb) + λ_regularize = unpack_rail!(optim_coils, packed, symmetric, bd) else # use NelderMead() ; other optimizer that works is Newton(), others have trouble res = Optim.optimize(placement_cost, packed, Optim.NelderMead(), Optim.Options(time_limit=60 * 2, iterations=maxiter, callback=clb); autodiff=:forward) if verbose println(res) end packed = Optim.minimizer(res) - λ_regularize = unpack_rail!(optim_coils, packed, symmetric, rb) + λ_regularize = unpack_rail!(optim_coils, packed, symmetric, bd) end return λ_regularize, trace @@ -589,10 +589,10 @@ function step(pfactor::PFcoilsOptActor; coil.time = pfactor.eq_in.time end - rb = pfactor.rb + bd = pfactor.bd # run rail type optimizer if optimization_scheme in [:rail, :static] - (λ_regularize, trace) = optimize_coils_rail(pfactor.eq_in; pinned_coils, optim_coils, fixed_coils, symmetric, λ_regularize, λ_ψ, λ_null, λ_currents, rb, maxiter, verbose) + (λ_regularize, trace) = optimize_coils_rail(pfactor.eq_in; pinned_coils, optim_coils, fixed_coils, symmetric, λ_regularize, λ_ψ, λ_null, λ_currents, bd, maxiter, verbose) else error("Supported PFcoilsOptActor optimization_scheme are `:static` or `:rail`") end @@ -647,8 +647,8 @@ Plot PFcoilsOptActor optimization cross-section end # setup plotting area - xlim = [0.0, maximum(pfactor.rb.layer[end].outline.r)] - ylim = [minimum(pfactor.rb.layer[end].outline.z), maximum(pfactor.rb.layer[end].outline.z)] + xlim = [0.0, maximum(pfactor.bd.layer[end].outline.r)] + ylim = [minimum(pfactor.bd.layer[end].outline.z), maximum(pfactor.bd.layer[end].outline.z)] xlim --> xlim * plot_r_buffer ylim --> ylim aspect_ratio --> :equal @@ -657,7 +657,7 @@ Plot PFcoilsOptActor optimization cross-section if build @series begin exclude_layers --> [:oh] - pfactor.rb + pfactor.bd end end @@ -708,7 +708,7 @@ Plot PFcoilsOptActor optimization cross-section @series begin outlines --> true exclude_layers --> [:oh] - pfactor.rb + pfactor.bd end end @@ -744,7 +744,7 @@ Plot PFcoilsOptActor optimization cross-section # plot optimization rails if rail - for (krail, rail) in enumerate(pfactor.rb.pf_coils_rail) + for (krail, rail) in enumerate(pfactor.bd.pf_coils_rail) if ! is_missing(rail.outline,:r) @series begin label --> (build ? "Coil opt. rail" : "")