Skip to content

Commit

Permalink
Merge pull request #300 from ProjectTorreyPines/sjk/macro1
Browse files Browse the repository at this point in the history
use metaprogramming to generate ParameterActors
  • Loading branch information
orso82 authored Apr 20, 2023
2 parents 9339a63 + af6a19d commit ea736a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 71 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FusionMaterials = "4c86da02-02c8-4634-8460-96566129f8e0"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
IMAS = "13ead8c1-b7d1-41bb-a6d0-5b8b65ed587a"
IMASDD = "06b86afa-9f21-11ec-2ef8-e51b8960cfc5"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JpegTurbo = "b835a17e-a41a-41e7-81f0-2f016b05efe0"
Expand Down
1 change: 0 additions & 1 deletion docs/src/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ The definition of each FUSE actor follows a well defined pattern.

```julia
# Definition of the `act` parameters relevant to the actor
# NOTE: To create a `ActorNAME` in `act` you'll have to add these to the FUSE/src/parameters_actors.jl file
Base.@kwdef mutable struct FUSEparameters__ActorNAME{T} <: ParametersActor where {T<:Real}
_parent::WeakRef = WeakRef(nothing)
_name::Symbol = :not_set
Expand Down
1 change: 1 addition & 0 deletions src/FUSE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using IMAS
import Plots
using Plots
using Printf
using InteractiveUtils
import SnoopPrecompile

#= ===== =#
Expand Down
103 changes: 33 additions & 70 deletions src/parameters_actors.jl
Original file line number Diff line number Diff line change
@@ -1,82 +1,45 @@
"""
insert_subtype_members T
Expands the subtypes into struct members
"""
macro insert_subtype_members(T)
expr = Expr(:block)
for s in subtypes(eval(T))
mem = Symbol(replace(String(Symbol(s)), "FUSE.FUSEparameters__"=>""))
constraint = Symbol(replace(String(Symbol(s)), "FUSE."=>""))
push!(expr.args, Expr(:(::), esc(mem), Expr(:curly, esc(constraint), esc(:T))))
end
expr
end

"""
@insert_constructor_members T
Returns a tuple of all the evaluated cosntructors for the
subtypes we can then splat into the larger constructor
"""
macro insert_constructor_members(T)
expr = Expr(:tuple)
for s in subtypes(eval(T))
mem = Symbol(replace(String(Symbol(s)), "FUSE."=>""))
push!(expr.args, Expr(:call, Expr(:curly, esc(mem), esc(:T))))
end
expr
end


mutable struct ParametersActors{T} <: ParametersAllActors where {T<:Real}
_parent::WeakRef
_name::Symbol
ActorCXbuild::FUSEparameters__ActorCXbuild{T}
ActorFluxSwing::FUSEparameters__ActorFluxSwing{T}
ActorLFSsizing::FUSEparameters__ActorLFSsizing{T}
ActorHFSsizing::FUSEparameters__ActorHFSsizing{T}
ActorStresses::FUSEparameters__ActorStresses{T}
ActorEquilibrium::FUSEparameters__ActorEquilibrium{T}
ActorSolovev::FUSEparameters__ActorSolovev{T}
ActorCHEASE::FUSEparameters__ActorCHEASE{T}
ActorPFcoilsOpt::FUSEparameters__ActorPFcoilsOpt{T}
ActorPassiveStructures::FUSEparameters__ActorPassiveStructures{T}
ActorBlanket::FUSEparameters__ActorBlanket{T}
ActorBalanceOfPlant::FUSEparameters__ActorBalanceOfPlant{T}
ActorPowerNeeds::FUSEparameters__ActorPowerNeeds{T}
ActorThermalCycle::FUSEparameters__ActorThermalCycle{T}
ActorHeatTransfer::FUSEparameters__ActorHeatTransfer{T}
ActorQEDcurrent::FUSEparameters__ActorQEDcurrent{T}
ActorSteadyStateCurrent::FUSEparameters__ActorSteadyStateCurrent{T}
ActorDivertors::FUSEparameters__ActorDivertors{T}
ActorNBsimple::FUSEparameters__ActorNBsimple{T}
ActorECsimple::FUSEparameters__ActorECsimple{T}
ActorICsimple::FUSEparameters__ActorICsimple{T}
ActorLHsimple::FUSEparameters__ActorLHsimple{T}
ActorTauenn::FUSEparameters__ActorTauenn{T}
ActorCosting::FUSEparameters__ActorCosting{T}
ActorNeutronics::FUSEparameters__ActorNeutronics{T}
ActorNeoclassical::FUSEparameters__ActorNeoclassical{T}
ActorFluxMatcher::FUSEparameters__ActorFluxMatcher{T}
ActorCoreTransport::FUSEparameters__ActorCoreTransport{T}
ActorFluxCalculator::FUSEparameters__ActorFluxCalculator{T}
ActorPedestal::FUSEparameters__ActorPedestal{T}
ActorTGLF::FUSEparameters__ActorTGLF{T}
ActorEquilibriumTransport::FUSEparameters__ActorEquilibriumTransport{T}
ActorWholeFacility::FUSEparameters__ActorWholeFacility{T}
ActorStabilityLimits::FUSEparameters__ActorStabilityLimits{T}
ActorHCD::FUSEparameters__ActorHCD{T}
@insert_subtype_members ParametersActor
end

function ParametersActors{T}() where {T<:Real}
act = ParametersActors{T}(
WeakRef(nothing),
:act,
FUSEparameters__ActorCXbuild{T}(),
FUSEparameters__ActorFluxSwing{T}(),
FUSEparameters__ActorLFSsizing{T}(),
FUSEparameters__ActorHFSsizing{T}(),
FUSEparameters__ActorStresses{T}(),
FUSEparameters__ActorEquilibrium{T}(),
FUSEparameters__ActorSolovev{T}(),
FUSEparameters__ActorCHEASE{T}(),
FUSEparameters__ActorPFcoilsOpt{T}(),
FUSEparameters__ActorPassiveStructures{T}(),
FUSEparameters__ActorBlanket{T}(),
FUSEparameters__ActorBalanceOfPlant{T}(),
FUSEparameters__ActorPowerNeeds{T}(),
FUSEparameters__ActorThermalCycle{T}(),
FUSEparameters__ActorHeatTransfer{T}(),
FUSEparameters__ActorQEDcurrent{T}(),
FUSEparameters__ActorSteadyStateCurrent{T}(),
FUSEparameters__ActorDivertors{T}(),
FUSEparameters__ActorNBsimple{T}(),
FUSEparameters__ActorECsimple{T}(),
FUSEparameters__ActorICsimple{T}(),
FUSEparameters__ActorLHsimple{T}(),
FUSEparameters__ActorTauenn{T}(),
FUSEparameters__ActorCosting{T}(),
FUSEparameters__ActorNeutronics{T}(),
FUSEparameters__ActorNeoclassical{T}(),
FUSEparameters__ActorFluxMatcher{T}(),
FUSEparameters__ActorCoreTransport{T}(),
FUSEparameters__ActorFluxCalculator{T}(),
FUSEparameters__ActorPedestal{T}(),
FUSEparameters__ActorTGLF{T}(),
FUSEparameters__ActorEquilibriumTransport{T}(),
FUSEparameters__ActorWholeFacility{T}(),
FUSEparameters__ActorStabilityLimits{T}(),
FUSEparameters__ActorHCD{T}()
(@insert_constructor_members ParametersActor)...
)
setup_parameters!(act)
return act
Expand Down

0 comments on commit ea736a0

Please sign in to comment.