Skip to content

Commit

Permalink
Merge pull request #1 from ProjectTorreyPines/touchups
Browse files Browse the repository at this point in the history
Touchups
  • Loading branch information
orso82 authored Oct 2, 2024
2 parents 55e0f9f + 5a43e69 commit 1118606
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 78 deletions.
12 changes: 12 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
margin = 180
always_for_in = true
for_in_replacement = "in"
annotate_untyped_fields_with_any = false
whitespace_in_kwargs = false
always_use_return = true
format_docstrings = true
remove_extra_newlines = false
trailing_comma = false
join_lines_based_on_source = true
separate_kwargs_with_semicolon = true
whitespace_ops_in_indices = false
10 changes: 10 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: CompatHelper

on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:

jobs:
CompatHelper:
uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/compat_helper.yml@master
33 changes: 33 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: "3"
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
14 changes: 14 additions & 0 deletions .github/workflows/make_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Make Docs

on:
pull_request:
branches: ["master"]
push:
branches:
- master
tags: '*'
workflow_dispatch:

jobs:
make_docs:
uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/make_docs.yml@master
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov

# Files generated by invoking Julia with --track-allocation
*.jl.mem

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/

# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/
docs/src/api.md

# PackageCompiler
build/

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml

# editors
/.vscode/*
.ipynb_checkpoints
.DS_Store

# temp/test files
test.json
asd.jl
31 changes: 31 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# BalanceOfPlantSurrogate.jl Notice

The purpose of this NOTICE file is to provide legal notices and acknowledgments that must be displayed to users in any derivative works or distributions. This file does not alter the terms of the Apache 2.0 license that governs the use and distribution of the BalanceOfPlantSurrogate.jl package.

## Development Attribution

BalanceOfPlantSurrogate.jl was originally developed under the FUSE project by the Magnetic Fusion Energy group at General Atomics.

## Citation

If this software contributes to an academic publication, please cite it as follows:

@article{meneghini2024fuse,
author = {Meneghini, O. and Slendebroek, T. and Lyons, B.C. and McLaughlin, K. and McClenaghan, J. and Stagner, L. and Harvey, J. and Neiser, T.F. and Ghiozzi, A. and Dose, G. and Guterl, J. and Zalzali, A. and Cote, T. and Shi, N. and Weisberg, D. and Smith, S.P. and Grierson, B.A. and Candy, J.},
doi = {10.48550/arXiv.2409.05894},
journal = {arXiv},
title = {{FUSE (Fusion Synthesis Engine): A Next Generation Framework for Integrated Design of Fusion Pilot Plants}},
year = {2024}
}

## Trademark Notice

The names "General Atomics", and any associated logos or images, are trademarks of General Atomics. Use of these trademarks without prior written consent from General Atomics is strictly prohibited. Users cannot imply endorsement by General Atomics or contributors to the project simply because the project is part of their work.

## Copyright

Copyright (c) 2024 General Atomics

## Version

**Version: v2.1**
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# BalanceOfPlantSurrogate
# BalanceOfPlantSurrogate.jl

The BalanceOfPlantSurrogate is a surogate model to the FUSE.ActorBalanceOfPlant actor in FUSE, this is done by simple interpolate/extrapolate of a hypercube
The BalanceOfPlantSurrogate is a surogate model to the FUSE.ActorBalanceOfPlant actor in FUSE, this is done by simple interpolate/extrapolate of a hypercube.

The data generation is done inside the ```BalanceOfPlantSurrogate/src/data``` folder , checkout the notebook in that folder!

To run the surogate model::
To run the surogate model:

```julia
using BalanceOfPlantSurrogate

bop_sur = BalanceOfPlantSurrogate.BOPSurogate(:rankine)
total_heat_load = 5e8
breeder_heat_load = 4e8
divertor_heat_load = 0.5e8
plant_efficiency = BalanceOfPlantSurrogate.predict_thermal_efficiency(bop_sur, total_heat_load, breeder_heat_load/total_heat_load, divertor_heat_load / (total_heat_load - breeder_heat_load))
BOP = BalanceOfPlantSurrogate.BOPSurogate(:rankine) # :rankine or :brayton
breeder_heat_load = 5e8
divertor_heat_load = 4e8
wall_heat_load = 0.5e8
plant_efficiency = BOP(breeder_heat_load, divertor_heat_load, wall_heat_load)
```
2 changes: 1 addition & 1 deletion data/BalanceOfPlantHypercubeN=10000.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cycle_type,total_power,breeder_heat_load,diverter_heatload,wall_heat_load,thermal_efficiency_cycle,thermal_efficiency_plant
cycle_type,total_heat_load,breeder_heat_load,divertor_heat_load,wall_heat_load,thermal_efficiency_cycle,thermal_efficiency_plant
rankine,1.0e6,0.5,0.1,0.9,0.34485874925643367,-0.26997501163143856
brayton,1.0e6,0.5,0.1,0.9,0.2700486923198959,-40.76786315148315
rankine,1.189841695416561e6,0.5,0.1,0.9,0.3460169377369303,-0.18345760358642882
Expand Down
2 changes: 1 addition & 1 deletion data/BalanceOfPlantHypercubeN=3600.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cycle_type,total_power,breeder_heat_load,diverter_heatload,wall_heat_load,thermal_efficiency_cycle,thermal_efficiency_plant
cycle_type,total_heat_load,breeder_heat_load,divertor_heat_load,wall_heat_load,thermal_efficiency_cycle,thermal_efficiency_plant
rankine,1.0e6,0.5,0.1,0.9,0.34485874925643367,-0.26997501163143856
brayton,1.0e6,0.5,0.1,0.9,0.2700486923198959,-40.76786315148315
rankine,1.3413764884981478e6,0.5,0.1,0.9,0.346920286374484,-0.13200304541344043
Expand Down
22 changes: 11 additions & 11 deletions data/PlotSurogate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"outputs": [],
"source": [
"# get the model and data\n",
"bop_sur_rankine = BalanceOfPlantSurogate.BOPSurogate(:rankine;data=\"BalanceOfPlantHypercubeN=10000.csv\")\n",
"bop_sur_brayton = BalanceOfPlantSurogate.BOPSurogate(:brayton;data=\"BalanceOfPlantHypercubeN=10000.csv\")\n",
"BOP_rankine = BalanceOfPlantSurogate.BOPSurogate(:rankine;data=\"BalanceOfPlantHypercubeN=10000.csv\")\n",
"BOP_brayton = BalanceOfPlantSurogate.BOPSurogate(:brayton;data=\"BalanceOfPlantHypercubeN=10000.csv\")\n",
"\n",
"BalanceOfPlantSurogate.predict_thermal_efficiency(bop_sur_rankine,1e8,0.5,0.2), BalanceOfPlantSurogate.predict_thermal_efficiency(bop_sur_brayton,1e8,0.5,0.2)"
"BalanceOfPlantSurogate.thermal_efficiency_fractions(BOP_rankine,1e8,0.5,0.2), BalanceOfPlantSurogate.thermal_efficiency_fractions(BOP_brayton,1e8,0.5,0.2)"
]
},
{
Expand All @@ -40,8 +40,8 @@
"outputs": [],
"source": [
"# plot the data\n",
"scatter(log10.(bop_sur_brayton.data.total_power),bop_sur_brayton.data.thermal_efficiency_plant,label=\"brayton\")\n",
"scatter!(log10.(bop_sur_rankine.data.total_power),bop_sur_rankine.data.thermal_efficiency_plant,ylim=(-1.0,1.0),label=\"rankine\",ylabel=\"thermal plant efficiency\",xlabel=\"total heat supplied\")\n"
"scatter(log10.(BOP_brayton.data.total_heat_load),BOP_brayton.data.thermal_efficiency_plant,label=\"brayton\")\n",
"scatter!(log10.(BOP_rankine.data.total_heat_load),BOP_rankine.data.thermal_efficiency_plant,ylim=(-1.0,1.0),label=\"rankine\",ylabel=\"thermal plant efficiency\",xlabel=\"total heat supplied\")\n"
]
},
{
Expand All @@ -61,11 +61,11 @@
"\n",
"total_heat_supplied = log10range(1e7,5e9,50)\n",
"\n",
"@manipulate for breeder_fraction in 0.5:0.025:0.9, diverter_fraction in 0.1:0.25:1.0\n",
" efficiencies = [BalanceOfPlantSurogate.predict_thermal_efficiency(bop_sur_brayton, p1, breeder_fraction, diverter_fraction) for p1 in total_heat_supplied]\n",
"@manipulate for breeder_fraction in 0.5:0.025:0.9, divertor_fraction in 0.1:0.25:1.0\n",
" efficiencies = [BalanceOfPlantSurogate.thermal_efficiency_fractions(BOP_brayton, p1, breeder_fraction, divertor_fraction) for p1 in total_heat_supplied]\n",
" plot(total_heat_supplied,efficiencies,marker=:circle, markersize=1, label=\"brayton\")\n",
"\n",
" efficiencies = [BalanceOfPlantSurogate.predict_thermal_efficiency(bop_sur_rankine, p1, breeder_fraction, diverter_fraction) for p1 in total_heat_supplied]\n",
" efficiencies = [BalanceOfPlantSurogate.thermal_efficiency_fractions(BOP_rankine, p1, breeder_fraction, divertor_fraction) for p1 in total_heat_supplied]\n",
" plot!(total_heat_supplied,efficiencies,marker=:circle, markersize=1, label=\"rankine\")\n",
" \n",
" plot!(xlabel=\"total heat supplied [W]\",ylabel=\"thermal plant efficiency\", ylim=(0.0,0.9), xscale=:log10,)\n",
Expand All @@ -81,16 +81,16 @@
},
"outputs": [],
"source": [
"#diverter_heat_fraction = 0.2 # You can adjust this value\n",
"#divertor_heat_fraction = 0.2 # You can adjust this value\n",
"cycle_lim = (0.0,0.6)\n",
"#total_heat_supplied = log10range(1e5,5e9,20)\n",
"\n",
"#@manipulate for breeder_fraction in 0.5:0.05:0.9, diverter_fraction in 0.1:0.05:1.0\n",
"#@manipulate for breeder_fraction in 0.5:0.05:0.9, divertor_fraction in 0.1:0.05:1.0\n",
"@manipulate for total_heat in log10range(1e5,5e9,20)\n",
" # Create a grid of values\n",
" breed = collect(0.5:0.05:0.9)\n",
" div = collect(0.1:0.05:1.0)\n",
" efficiencies = [BalanceOfPlantSurogate.predict_thermal_efficiency(bop_sur_brayton, total_heat, p1,p2)\n",
" efficiencies = [BalanceOfPlantSurogate.thermal_efficiency_fractions(BOP_brayton, total_heat, p1,p2)\n",
" for p1 in breed, p2 in div]\n",
"# @show efficiencies\n",
" surface(breed, div, efficiencies',\n",
Expand Down
38 changes: 19 additions & 19 deletions data/generate_hypercube.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using ProgressMeter

FUSE.logging(Logging.Info; actors=Logging.Error);

mutable struct BalanceOfPlantHyperCubee
mutable struct BalanceOfPlantHyperCube
cases::AbstractArray
df::Union{DataFrames.DataFrame,Nothing}
end
Expand All @@ -18,22 +18,22 @@ end
Initialize the balance of plant hypercube
The power to each system is done like:
total_power
| | (1 - breeder_fraction)
breeder div+wall
| | (1 - div_fraciton)
div wallexit()
total
| | (1 - breeder_fraction)
breeder div+wall
| | (1 - div_fraciton)
div wall
"""
function generate_hypercube(; var_steps::Int=2, cycle_types::Vector{Symbol}=[:rankine, :brayton],
power_range=(lower=1e6, upper=1e9), breeder_heat_load_fraction_range=(lower=0.5, upper=0.99),
divertor_heat_load_fraction_range=(lower=0.1, upper=0.9))

power_scan = log10range(power_range.lower, power_range.upper, var_steps)
breeder_scan = LinRange(breeder_heat_load_fraction_range.lower, breeder_heat_load_fraction_range.upper, var_steps)
diverter_scan = LinRange(divertor_heat_load_fraction_range.lower, divertor_heat_load_fraction_range.upper, var_steps)
divertor_scan = LinRange(divertor_heat_load_fraction_range.lower, divertor_heat_load_fraction_range.upper, var_steps)

cases = collect(Iterators.product(cycle_types, power_scan, breeder_scan, diverter_scan))
return BalanceOfPlantHyperCubee(cases, nothing)
cases = collect(Iterators.product(cycle_types, power_scan, breeder_scan, divertor_scan))
return BalanceOfPlantHyperCube(cases, nothing)
end


Expand All @@ -42,7 +42,7 @@ function log10range(start_value, stop_value, num_points)
end


function workflow_case(cycle_type::Symbol, total_power::Float64, bf::Float64, df::Float64)
function workflow_case(cycle_type::Symbol, total_heat_load::Float64, bf::Float64, df::Float64)

dd = IMAS.dd()
act = FUSE.ParametersActors()
Expand All @@ -53,26 +53,26 @@ function workflow_case(cycle_type::Symbol, total_power::Float64, bf::Float64, df
dd.global_time = 0.0

non_bf = 1.0 - bf
@ddtime(bop.power_plant.heat_load.breeder = bf * total_power)
@ddtime(bop.power_plant.heat_load.divertor = non_bf * total_power * df)
@ddtime (bop.power_plant.heat_load.wall = non_bf * total_power * (1.0 - df))
@ddtime(bop.power_plant.heat_load.breeder = bf * total_heat_load)
@ddtime(bop.power_plant.heat_load.divertor = non_bf * total_heat_load * df)
@ddtime(bop.power_plant.heat_load.wall = non_bf * total_heat_load * (1.0 - df))

act.ActorThermalPlant.model = :network
bop.power_plant.power_cycle_type = string(cycle_type)
FUSE.ActorThermalPlant(dd, act)

thermal_eff_cycle = @ddtime (bop.thermal_efficiency_cycle)
thermal_eff_plant = @ddtime (bop.thermal_efficiency_plant)
thermal_eff_cycle = @ddtime(bop.thermal_efficiency_cycle)
thermal_eff_plant = @ddtime(bop.thermal_efficiency_plant)

return (cycle_type, total_power, bf, df, 1 - df, thermal_eff_cycle, thermal_eff_plant)
return (cycle_type, total_heat_load, bf, df, 1 - df, thermal_eff_cycle, thermal_eff_plant)
end

"""
run_hypercube!(hyper_cube::BalanceOfPlantHyperCubee, save_folder::String)
run_hypercube!(hyper_cube::BalanceOfPlantHyperCube, save_folder::String)
Runs the hypercube with pmap or map depending if you loaded Distributed
"""
function run_hypercube!(hyper_cube::BalanceOfPlantHyperCubee, save_folder::String)
function run_hypercube!(hyper_cube::BalanceOfPlantHyperCube, save_folder::String)
println()
if @isdefined Distributed
println("running $(length(hyper_cube.cases)) cases on $(nworkers()) workers")
Expand All @@ -82,7 +82,7 @@ function run_hypercube!(hyper_cube::BalanceOfPlantHyperCubee, save_folder::Strin
results = @showprogress map(case -> workflow_case(case...), hyper_cube.cases)
end

hyper_cube.df = DataFrame(results, [:cycle_type, :total_power, :breeder_heat_load, :diverter_heatload, :wall_heat_load, :thermal_efficiency_cycle, :thermal_efficiency_plant])
hyper_cube.df = DataFrame(results, [:cycle_type, :total_heat_load, :breeder_heat_load, :divertor_heat_load, :wall_heat_load, :thermal_efficiency_cycle, :thermal_efficiency_plant])

CSV.write(joinpath(save_folder, "BalanceOfPlantHypercubeN=$(length(hyper_cube.df.thermal_efficiency_plant)).csv"), hyper_cube.df)

Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
BalanceOfPlantSurrogate = "001e48cb-5a1e-4e3c-a5d4-cdc3aa14f3de"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
43 changes: 43 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Documenter, BalanceOfPlantSurrogate

# Call functions
open(joinpath(@__DIR__, "src/api.md"), "w") do f
println(f, "# API Reference\n")
for page in keys(BalanceOfPlantSurrogate.document)
if page == :Expressions
continue
end
println(f, "## $page\n")
println(f, "```@docs")
for item in BalanceOfPlantSurrogate.document[page]
println(f, "$item")
end
println(f, "```")
end
end

makedocs(;
modules=[BalanceOfPlantSurrogate],
format=Documenter.HTML(),
sitename="BalanceOfPlantSurrogate",
checkdocs=:none,
pages=["index.md", "api.md", "License" => "license.md", "Notice" => "notice.md"]
)

# Deploy docs
# This function deploys the documentation to the gh-pages branch of the repository.
# The main documentation that will be hosted on
# https://projecttorreypines.github.io/BalanceOfPlantSurrogate.jl/stable
# will be built from latest release tagged with a version number.
# The development documentation that will be hosted on
# https://projecttorreypines.github.io/BalanceOfPlantSurrogate.jl/dev
# will be built from the latest commit on the chosen devbranch argument below.
# For testing purposes, the devbranch argument can be set to WIP branch like "docs".
# While merging with master, the devbranch argument should be set to "master".
deploydocs(;
repo="github.com/ProjectTorreyPines/BalanceOfPlantSurrogate.jl.git",
target="build",
branch="gh-pages",
devbranch="master",
versions=["stable" => "v^", "v#.#"]
)
1 change: 1 addition & 0 deletions docs/src/index.md
1 change: 1 addition & 0 deletions docs/src/license.md
1 change: 1 addition & 0 deletions docs/src/notice.md
Loading

0 comments on commit 1118606

Please sign in to comment.