Skip to content

Commit

Permalink
Merge pull request #95 from MineralsCloud:choose-volume
Browse files Browse the repository at this point in the history
Use `_choose` in `customizer` in src/EquationOfStateWorkflow/actions.jl
  • Loading branch information
singularitti committed Jan 17, 2022
2 parents 3b31831 + cb2353b commit 74e11d9
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit 74e11d9

Please sign in to comment.