Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eldond committed Sep 25, 2023
1 parent 64c04de commit 06179e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
27 changes: 14 additions & 13 deletions src/actuator_model.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Actuator models to translate commands (probably in V) into gas flows

using PhysicalConstants.CODATA2018
import Unitful
using Unitful: Unitful
using Interpolations: Interpolations
import YAML
using YAML: YAML

"""
gas_unit_converter()
Expand All @@ -13,15 +13,16 @@ Pressure * volume type flows / quantities and count / current types of units.
Output will be unitful; take output.val if you do no want the units attached.
"""
function gas_unit_converter(
value_in, units_in, units_out; species::String="H", temperature=293.15 * Unitful.K
value_in, units_in, units_out; species::String="H", temperature=293.15 * Unitful.K,
)
if units_in == units_out
return value_in
end

# Multiply by gas flow to convert Torr L/s to Pa m^3/s
torrl_to_pam3 = 0.133322368 * Unitful.Pa * Unitful.m^3 / Unitful.Torr / Unitful.L
pam3_to_molecules = Unitful.J / (temperature * BoltzmannConstant) / (Unitful.Pa * Unitful.m^3)
pam3_to_molecules =
Unitful.J / (temperature * BoltzmannConstant) / (Unitful.Pa * Unitful.m^3)
torrl_to_molecules = torrl_to_pam3 * pam3_to_molecules
atoms_per_molecule = Dict(
"H" => 1 * 2, # Assumed to mean H2. How would you even puff a bunch of H1.
Expand Down Expand Up @@ -58,18 +59,18 @@ function gas_unit_converter(
"C" => ElementaryCharge / atoms_per_molecule[species],
)
if haskey(factor_to_get_molecules_s, units_in)
conversion_factor = factor_to_get_molecules_s[units_in] / factor_to_get_molecules_s[units_out]
conversion_factor =
factor_to_get_molecules_s[units_in] / factor_to_get_molecules_s[units_out]
elseif haskey(factor_to_get_molecules, units_in)
conversion_factor = factor_to_get_molecules[units_in] / factor_to_get_molecules[units_out]
conversion_factor =
factor_to_get_molecules[units_in] / factor_to_get_molecules[units_out]
else
throw(ArgumentError("Unrecognized units: " * units_in))
end
return value_in .* conversion_factor
end

function select_default_config(model::String)
return model * "_gas_valve.yml"
end
select_default_config(model::String) = model * "_gas_valve.yml"

"""
model_gas_valve()
Expand All @@ -78,7 +79,7 @@ The main function for handling a gas valve model. Has logic for selecting models
and configurations.
"""
function model_gas_valve(
t, command, model::String; configuration_file::String="auto", species::String="D2"
t, command, model::String; configuration_file::String="auto", species::String="D2",
)
# Select configuration file
if configuration_file == "auto"
Expand Down Expand Up @@ -110,7 +111,7 @@ function model_gas_valve(
end

function instant_gas_model(command, config)
return config["p1"] .* (sqrt.(((command * config["p2"]).^2.0.+1).-1))
return config["p1"] .* (sqrt.(((command * config["p2"]) .^ 2.0 .+ 1) .- 1))
end

function lowpass_filter_(raw, previous_smooth, dt, tau)
Expand All @@ -119,7 +120,7 @@ end

function lowpass_filter(t, x, tau)
xs = zeros(length(t))
for i = 2:length(t)
for i 2:length(t)
xs[i] = lowpass_filter_(x[i], xs[i-1], t[i] - t[i-1], tau)
end
return xs
Expand All @@ -133,5 +134,5 @@ function simple_gas_model(t, command, config)
prepend!(flow0_ext, flow0[1])
interp = Interpolations.LinearInterpolation(t_ext, flow0_ext)
delayed_flow = interp.(t .- config["delay"])
flow = lowpass_filter(t, delayed_flow, config["tau"])
return flow = lowpass_filter(t, delayed_flow, config["tau"])
end
17 changes: 13 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using OMAS: OMAS
using EFIT: EFIT
using Plots
using Test
import Unitful
using Unitful: Unitful

"""
make_test_profile()
Expand Down Expand Up @@ -71,14 +71,23 @@ function define_default_sample_set()
return b2fgmtry, b2time, b2mn, gridspec, eqdsk
end


@testset "lightweight_utilities" begin
# Gas unit converter
flow_tls = 40.63 * Unitful.Torr * Unitful.L / Unitful.s
flow_pam3 = SD4SOLPS.gas_unit_converter(flow_tls, "torr L s^-1", "Pa m^3 s^-1")
@test flow_pam3.val > 0.0
flow_molecules1 = SD4SOLPS.gas_unit_converter(flow_tls, "torr L s^-1", "molecules s^-1", temperature=293.15 * Unitful.K)
flow_molecules2 = SD4SOLPS.gas_unit_converter(flow_tls, "torr L s^-1", "molecules s^-1", temperature=300.0 * Unitful.K)
flow_molecules1 = SD4SOLPS.gas_unit_converter(
flow_tls,
"torr L s^-1",
"molecules s^-1";
temperature=293.15 * Unitful.K,
)
flow_molecules2 = SD4SOLPS.gas_unit_converter(
flow_tls,
"torr L s^-1",
"molecules s^-1";
temperature=300.0 * Unitful.K,
)
@test flow_molecules1 > flow_molecules2
end

Expand Down

0 comments on commit 06179e1

Please sign in to comment.