Skip to content

Commit

Permalink
Merge pull request #192 from portyanikhin/add-ability-to-specify-phase
Browse files Browse the repository at this point in the history
Added the ability to specify the phase for fluids and mixtures
  • Loading branch information
portyanikhin authored Aug 4, 2023
2 parents 2df370d + 1bbe8f0 commit 70ed84e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
15 changes: 15 additions & 0 deletions SharpProp.Tests/Fluids/FluidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ public void Reset_Always_ResetsAllNonTrivialProperties()
.WithMessage("Invalid or not defined state!");
}

[Fact]
public void SpecifyPhase_Always_SpecifiesPhaseForAllFurtherCalculations()
{
IAbstractFluid fluid = _fluid;
fluid.SpecifyPhase(Phases.Gas);
var action = () =>
fluid.Update(
Input.Pressure(1.Atmospheres()),
Input.Temperature(20.DegreesCelsius())
);
action.Should().Throw<ApplicationException>();
fluid.UnspecifyPhase();
action.Should().NotThrow();
}

[Fact]
public void WithState_WaterInStandardConditions_PhaseIsLiquid() =>
_fluid
Expand Down
4 changes: 4 additions & 0 deletions SharpProp.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
x:Key="/Default/UserDictionary/Words/=Undecane/@EntryIndexedValue">
True
</s:Boolean>
<s:Boolean
x:Key="/Default/UserDictionary/Words/=Unspecify/@EntryIndexedValue">
True
</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=volu/@EntryIndexedValue">
True
</s:Boolean>
Expand Down
14 changes: 13 additions & 1 deletion SharpProp/CoolProp/AbstractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ double secondInput
SwigExceptions.ThrowPendingException();
}

public virtual void Clear()
public void Clear()
{
AbstractStatePInvoke.Clear(_handle);
SwigExceptions.ThrowPendingException();
}

public void SpecifyPhase(Phases phase)
{
AbstractStatePInvoke.SpecifyPhase(_handle, (int)phase);
SwigExceptions.ThrowPendingException();
}

public void UnspecifyPhase()
{
AbstractStatePInvoke.UnspecifyPhase(_handle);
SwigExceptions.ThrowPendingException();
}

public double KeyedOutput(Parameters key)
{
var result = AbstractStatePInvoke.KeyedOutput(_handle, (int)key);
Expand Down
9 changes: 9 additions & 0 deletions SharpProp/CoolProp/AbstractStatePInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ double secondInput
[DllImport(Library.Name, EntryPoint = "CSharp_AbstractState_clear")]
public static extern bool Clear(HandleRef abstractState);

[DllImport(Library.Name, EntryPoint = "CSharp_AbstractState_specify_phase")]
public static extern void SpecifyPhase(HandleRef abstractState, int phase);

[DllImport(
Library.Name,
EntryPoint = "CSharp_AbstractState_unspecify_phase"
)]
public static extern void UnspecifyPhase(HandleRef abstractState);

[DllImport(Library.Name, EntryPoint = "CSharp_AbstractState_keyed_output")]
public static extern double KeyedOutput(HandleRef abstractState, int key);
}
4 changes: 4 additions & 0 deletions SharpProp/Fluids/AbstractFluid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public virtual void Reset()
_phase = null;
}

public void SpecifyPhase(Phases phase) => Backend.SpecifyPhase(phase);

public void UnspecifyPhase() => Backend.UnspecifyPhase();

[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode() =>
(
Expand Down
12 changes: 12 additions & 0 deletions SharpProp/Fluids/IAbstractFluid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ IKeyedInput<Parameters> secondInput
/// Resets all non-trivial properties.
/// </summary>
public void Reset();

/// <summary>
/// Specify the phase state for all further calculations.
/// </summary>
/// <param name="phase">Phase state.</param>
public void SpecifyPhase(Phases phase);

/// <summary>
/// Unspecify the phase state and
/// go back to calculating it based on the inputs.
/// </summary>
public void UnspecifyPhase();
}

0 comments on commit 70ed84e

Please sign in to comment.