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

Input time dependent signals for time dependent simulation #402

Merged
merged 46 commits into from
Sep 7, 2023
Merged

Conversation

orso82
Copy link
Member

@orso82 orso82 commented Aug 29, 2023

FUSE input ini now supports input of time dependent quantities.

Few handy functions make it quite convenient to specify complex behaviors fe39669

for example:

ini.equilibrium.ip = t -> @. trap(t/100.0, 0.9)*8E6 + (ramp(t, 25.0, 25.0) - ramp(t, 100-25.0, 25.0) + sin((t-50.0)*2π/25.0*3.5)*pulse(t, 50.0, 25.0))*1E6
image

cases/FPPv2.jl Outdated
@@ -60,7 +60,7 @@ function case_parameters(::Type{Val{:FPPv2}})::Tuple{ParametersAllInits,Paramete
ini.equilibrium.κ = 0.8826
ini.equilibrium.δ = 0.7
ini.equilibrium.pressure_core = 1.2e6
ini.equilibrium.ip = 8.0e6
ini.equilibrium.ip = t -> @. trap(t / Δt, 0.9) * 8.0e6 + trap((t - Δt / 4) / (Δt / 2), 0.75) * 1.0E6 - trap((t - Δt * 3 / 8) / (Δt / 4), 0.25) * 2.0E6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather that putting @. inside the function, it would be better to treat it as a scalar and then have the user call ini.equilibrium.ip.(t) if t is an array.

# first run primes for second run
res = Optim.optimize(
x0 -> cost(x0),
[OH.thickness, TFhfs.thickness, dd.build.oh.technology.fraction_steel, dd.build.tf.technology.fraction_steel],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates a small array. Probably trivial, but a Tuple or SVector would be better if they work.


Initialize `dd.pulse_schedule` starting from `ini` and `act` parameters
"""
function init_pulse_schedule(dd::IMAS.dd, ini::ParametersAllInits, act::ParametersAllActors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init_pulse_schedule!(dd, ini, act)? since it modifies dd?

κ::Entry{T} = Entry{T}("-", "Plasma elongation. NOTE: If < 1.0 it defines the fraction of maximum controllable elongation estimate.")
δ::Entry{T} = Entry{T}(IMAS.equilibrium__time_slice___boundary, :triangularity)
ζ::Entry{T} = Entry{T}(IMAS.equilibrium__time_slice___boundary, :squareness; default=0.0)
B0::Entry{Union{Function,T}} = Entry{Union{Function,T}}(IMAS.equilibrium__vacuum_toroidal_field, :b0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this all type stable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I would not do @. like this inside functions. The user should call them as step.(t), etc.

src/signal.jl Outdated
function ramp(t::T)::T where T
a = @. t * (t < 1) * (t > 0)
b = @. t >= 1
return @. a + b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is more than just style. If t is an array, a and b will allocate here. If it was called as ramp.(t), they would not be allocated.

@orso82 orso82 merged commit a3a5766 into master Sep 7, 2023
@orso82 orso82 deleted the input_time branch September 7, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants