diff --git a/Project.toml b/Project.toml index 7e7272e55..9eef472cc 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/docs/src/develop.md b/docs/src/develop.md index 60dfbca51..580b0e498 100644 --- a/docs/src/develop.md +++ b/docs/src/develop.md @@ -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 diff --git a/src/FUSE.jl b/src/FUSE.jl index a82c5041d..80bacd30e 100644 --- a/src/FUSE.jl +++ b/src/FUSE.jl @@ -6,6 +6,7 @@ using IMAS import Plots using Plots using Printf +using InteractiveUtils import SnoopPrecompile #= ===== =# diff --git a/src/parameters_actors.jl b/src/parameters_actors.jl index b06e8ba3b..ce628d47a 100644 --- a/src/parameters_actors.jl +++ b/src/parameters_actors.jl @@ -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