diff --git a/src/SharpProp/Fluids/AbstractFluid.cs b/src/SharpProp/Fluids/AbstractFluid.cs index 922b3d4..6731ec5 100644 --- a/src/SharpProp/Fluids/AbstractFluid.cs +++ b/src/SharpProp/Fluids/AbstractFluid.cs @@ -43,9 +43,17 @@ public virtual void Reset() _phase = null; } - public void SpecifyPhase(Phases phase) => Backend.SpecifyPhase(phase); + protected AbstractFluid SpecifyPhase(Phases phase) + { + Backend.SpecifyPhase(phase); + return this; + } - public void UnspecifyPhase() => Backend.UnspecifyPhase(); + protected AbstractFluid UnspecifyPhase() + { + Backend.UnspecifyPhase(); + return this; + } [SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] public override int GetHashCode() => diff --git a/src/SharpProp/Fluids/Fluid.cs b/src/SharpProp/Fluids/Fluid.cs index b1e0d8d..bde412d 100644 --- a/src/SharpProp/Fluids/Fluid.cs +++ b/src/SharpProp/Fluids/Fluid.cs @@ -45,6 +45,10 @@ fraction is not null public Ratio Fraction { get; } + public new IFluid SpecifyPhase(Phases phase) => (Fluid)base.SpecifyPhase(phase); + + public new IFluid UnspecifyPhase() => (Fluid)base.UnspecifyPhase(); + public new IFluid WithState( IKeyedInput firstInput, IKeyedInput secondInput diff --git a/src/SharpProp/Fluids/IAbstractFluid.cs b/src/SharpProp/Fluids/IAbstractFluid.cs index aae11fa..0af7cb9 100644 --- a/src/SharpProp/Fluids/IAbstractFluid.cs +++ b/src/SharpProp/Fluids/IAbstractFluid.cs @@ -17,16 +17,4 @@ public interface IAbstractFluid : IFluidState, IDisposable /// Resets all non-trivial properties. /// void Reset(); - - /// - /// Specify the phase state for all further calculations. - /// - /// Phase state. - void SpecifyPhase(Phases phase); - - /// - /// Unspecify the phase state and - /// go back to calculating it based on the inputs. - /// - void UnspecifyPhase(); } diff --git a/src/SharpProp/Fluids/IFluid.cs b/src/SharpProp/Fluids/IFluid.cs index 1ff31ec..d164af6 100644 --- a/src/SharpProp/Fluids/IFluid.cs +++ b/src/SharpProp/Fluids/IFluid.cs @@ -21,6 +21,19 @@ public interface IFluid /// Ratio Fraction { get; } + /// + /// Specify the phase state for all further calculations. + /// + /// Phase state. + /// Current fluid instance. + IFluid SpecifyPhase(Phases phase); + + /// + /// Unspecify the phase state and go back to calculating it based on the inputs. + /// + /// Current fluid instance. + IFluid UnspecifyPhase(); + /// /// Returns a new fluid instance with a defined state. /// diff --git a/src/SharpProp/Fluids/IMixture.cs b/src/SharpProp/Fluids/IMixture.cs index 12727ec..a4475d3 100644 --- a/src/SharpProp/Fluids/IMixture.cs +++ b/src/SharpProp/Fluids/IMixture.cs @@ -20,6 +20,19 @@ public interface IMixture /// IReadOnlyList Fractions { get; } + /// + /// Specify the phase state for all further calculations. + /// + /// Phase state. + /// Current mixture instance. + IMixture SpecifyPhase(Phases phase); + + /// + /// Unspecify the phase state and go back to calculating it based on the inputs. + /// + /// Current mixture instance. + IMixture UnspecifyPhase(); + /// /// Returns a new mixture instance with a defined state. /// diff --git a/src/SharpProp/Fluids/Mixture.cs b/src/SharpProp/Fluids/Mixture.cs index fb67c42..44f1d46 100644 --- a/src/SharpProp/Fluids/Mixture.cs +++ b/src/SharpProp/Fluids/Mixture.cs @@ -66,6 +66,10 @@ public Mixture(IEnumerable fluids, IEnumerable fractions) public IReadOnlyList Fractions { get; } + public new IMixture SpecifyPhase(Phases phase) => (Mixture)base.SpecifyPhase(phase); + + public new IMixture UnspecifyPhase() => (Mixture)base.UnspecifyPhase(); + public new IMixture WithState( IKeyedInput firstInput, IKeyedInput secondInput diff --git a/tests/SharpProp.Tests/Fluids/FluidTests.cs b/tests/SharpProp.Tests/Fluids/FluidTests.cs index c215632..274f0d4 100644 --- a/tests/SharpProp.Tests/Fluids/FluidTests.cs +++ b/tests/SharpProp.Tests/Fluids/FluidTests.cs @@ -160,12 +160,11 @@ public void Reset_Always_ResetsAllNonTrivialProperties() [Fact] public void SpecifyPhase_Always_SpecifiesPhaseForAllFurtherCalculations() { - IAbstractFluid fluid = _fluid; - fluid.SpecifyPhase(Phases.Gas); + _fluid.SpecifyPhase(Phases.Gas); var action = () => - fluid.Update(Input.Pressure(1.Atmospheres()), Input.Temperature(20.DegreesCelsius())); + _fluid.Update(Input.Pressure(1.Atmospheres()), Input.Temperature(20.DegreesCelsius())); action.Should().Throw(); - fluid.UnspecifyPhase(); + _fluid.UnspecifyPhase(); action.Should().NotThrow(); } diff --git a/tests/SharpProp.Tests/Fluids/MixtureTests.cs b/tests/SharpProp.Tests/Fluids/MixtureTests.cs index c7b731b..12b7926 100644 --- a/tests/SharpProp.Tests/Fluids/MixtureTests.cs +++ b/tests/SharpProp.Tests/Fluids/MixtureTests.cs @@ -46,6 +46,20 @@ public void Update_Always_InputsAreCached() mixture.Temperature.Kelvins.Should().Be(293.15); } + [Fact] + public void SpecifyPhase_Always_SpecifiesPhaseForAllFurtherCalculations() + { + _mixture.SpecifyPhase(Phases.Gas); + var action = () => + _mixture.Update( + Input.Pressure(1.Atmospheres()), + Input.Temperature(20.DegreesCelsius()) + ); + action.Should().Throw(); + _mixture.UnspecifyPhase(); + action.Should().NotThrow(); + } + [Fact] public void WithState_VodkaInStandardConditions_PhaseIsLiquid() => _mixture