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

Use _choose in customizer in src/EquationOfStateWorkflow/actions.jl #95

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/EquationOfStateWorkflow/actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ end
customizer(volume::Volume, timefmt = "Y-m-d_H:M:S") =
OutdirSetter(timefmt) ∘ VolumeSetter(volume)
function customizer(eos::PressureEquation, pressure::Pressure, timefmt = "Y-m-d_H:M:S")
volumes = vsolve(eos, pressure)
volume = length(volumes) > 1 ? _interactive_choose(volumes) : only(volumes)
possible_volumes = vsolve(eos, pressure)
volume =
length(possible_volumes) > 1 ? _choose(possible_volumes, pressure, eos) :
only(possible_volumes)
return OutdirSetter(timefmt) ∘ PressureSetter(pressure) ∘ VolumeSetter(volume)
end
customizer(params::Parameters, pressure::Pressure, timefmt = "Y-m-d_H:M:S") =
Expand All @@ -61,6 +63,16 @@ customizer(params::Parameters, pressure::Pressure, timefmt = "Y-m-d_H:M:S") =
(x::RunCmd)(input, output = mktemp(parentdir(input))[1]; kwargs...) =
pw(input, output; kwargs...)

function _choose(possible_volumes, pressure, eos)
v0 = getparam(eos).v0
filtered = if pressure >= zero(pressure) # If pressure is greater than zero,
filter(<(v0), possible_volumes) # the volume could only be smaller than `v0`.
else
filter(>(v0), possible_volumes)
end
return only(filtered)
end

function _interactive_choose(volumes)
options = string.(volumes)
menu = RadioMenu(options)
Expand Down