From 06179e19c4b0c25801e8407d7cbb4b49673a7c49 Mon Sep 17 00:00:00 2001 From: David Eldon Date: Mon, 25 Sep 2023 10:45:06 -0700 Subject: [PATCH] Fix formatting --- src/actuator_model.jl | 27 ++++++++++++++------------- test/runtests.jl | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/actuator_model.jl b/src/actuator_model.jl index 845b0ee..e19b4f9 100644 --- a/src/actuator_model.jl +++ b/src/actuator_model.jl @@ -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() @@ -13,7 +13,7 @@ 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 @@ -21,7 +21,8 @@ function gas_unit_converter( # 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. @@ -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() @@ -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" @@ -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) @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 8dc2765..200fe29 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,7 @@ using OMAS: OMAS using EFIT: EFIT using Plots using Test -import Unitful +using Unitful: Unitful """ make_test_profile() @@ -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