Skip to content

Commit f4ef31a

Browse files
committed
refactor: merge interfaces into implementation files
1 parent 7798f78 commit f4ef31a

14 files changed

Lines changed: 793 additions & 800 deletions

src/SharpProp/Fluids/AbstractFluid.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
namespace SharpProp;
44

5+
/// <summary>
6+
/// Abstract fluid.
7+
/// </summary>
8+
public interface IAbstractFluid : IFluidState, IDisposable
9+
{
10+
/// <summary>
11+
/// Updates the state of the fluid.
12+
/// </summary>
13+
/// <param name="firstInput">First input property.</param>
14+
/// <param name="secondInput">Second input property.</param>
15+
/// <exception cref="ArgumentException">Need to define 2 unique inputs!</exception>
16+
void Update(IKeyedInput<Parameters> firstInput, IKeyedInput<Parameters> secondInput);
17+
18+
/// <summary>
19+
/// Resets all non-trivial properties.
20+
/// </summary>
21+
void Reset();
22+
}
23+
524
/// <inheritdoc cref="IAbstractFluid"/>
625
public abstract partial class AbstractFluid : IAbstractFluid
726
{

src/SharpProp/Fluids/Fluid.cs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,218 @@
22

33
namespace SharpProp;
44

5+
/// <summary>
6+
/// Pure/pseudo-pure fluid or binary mixture.
7+
/// </summary>
8+
public interface IFluid
9+
: IAbstractFluid,
10+
IClonable<IFluid>,
11+
IEquatable<IFluid>,
12+
IFactory<IFluid>,
13+
IJsonable
14+
{
15+
/// <summary>
16+
/// Selected fluid name.
17+
/// </summary>
18+
FluidsList Name { get; }
19+
20+
/// <summary>
21+
/// Mass-based or volume-based fraction
22+
/// for binary mixtures (by default, %).
23+
/// </summary>
24+
Ratio Fraction { get; }
25+
26+
/// <summary>
27+
/// Type of CoolProp backend.
28+
/// </summary>
29+
string CoolPropBackend { get; }
30+
31+
/// <summary>
32+
/// Specify the phase state for all further calculations.
33+
/// </summary>
34+
/// <param name="phase">Phase state.</param>
35+
/// <returns>Current fluid instance.</returns>
36+
IFluid SpecifyPhase(Phases phase);
37+
38+
/// <summary>
39+
/// Unspecify the phase state and go back to calculating it based on the inputs.
40+
/// </summary>
41+
/// <returns>Current fluid instance.</returns>
42+
IFluid UnspecifyPhase();
43+
44+
/// <summary>
45+
/// Returns a new fluid instance with a defined state.
46+
/// </summary>
47+
/// <param name="firstInput">First input property.</param>
48+
/// <param name="secondInput">Second input property.</param>
49+
/// <returns>A new fluid instance with a defined state.</returns>
50+
/// <exception cref="ArgumentException">Need to define 2 unique inputs!</exception>
51+
IFluid WithState(IKeyedInput<Parameters> firstInput, IKeyedInput<Parameters> secondInput);
52+
53+
/// <summary>
54+
/// The process of isentropic compression to given pressure.
55+
/// </summary>
56+
/// <param name="pressure">Pressure.</param>
57+
/// <returns>The state of the fluid at the end of the process.</returns>
58+
/// <exception cref="ArgumentException">
59+
/// Compressor outlet pressure should be higher than inlet pressure!
60+
/// </exception>
61+
IFluid IsentropicCompressionTo(Pressure pressure);
62+
63+
/// <summary>
64+
/// The process of compression to given pressure.
65+
/// </summary>
66+
/// <param name="pressure">Pressure.</param>
67+
/// <param name="isentropicEfficiency">Compressor isentropic efficiency.</param>
68+
/// <returns>The state of the fluid at the end of the process.</returns>
69+
/// <exception cref="ArgumentException">
70+
/// Compressor outlet pressure should be higher than inlet pressure!
71+
/// </exception>
72+
/// <exception cref="ArgumentException">Invalid compressor isentropic efficiency!</exception>
73+
IFluid CompressionTo(Pressure pressure, Ratio isentropicEfficiency);
74+
75+
/// <summary>
76+
/// The process of isenthalpic expansion to given pressure.
77+
/// </summary>
78+
/// <param name="pressure">Pressure.</param>
79+
/// <returns>The state of the fluid at the end of the process.</returns>
80+
/// <exception cref="ArgumentException">
81+
/// Expansion valve outlet pressure should be lower than inlet pressure!
82+
/// </exception>
83+
IFluid IsenthalpicExpansionTo(Pressure pressure);
84+
85+
/// <summary>
86+
/// The process of isentropic expansion to given pressure.
87+
/// </summary>
88+
/// <param name="pressure">Pressure.</param>
89+
/// <returns>The state of the fluid at the end of the process.</returns>
90+
/// <exception cref="ArgumentException">
91+
/// Expander outlet pressure should be lower than inlet pressure!
92+
/// </exception>
93+
IFluid IsentropicExpansionTo(Pressure pressure);
94+
95+
/// <summary>
96+
/// The process of expansion to given pressure.
97+
/// </summary>
98+
/// <param name="pressure">Pressure.</param>
99+
/// <param name="isentropicEfficiency">Expander isentropic efficiency.</param>
100+
/// <returns>The state of the fluid at the end of the process.</returns>
101+
/// <exception cref="ArgumentException">
102+
/// Expander outlet pressure should be lower than inlet pressure!
103+
/// </exception>
104+
/// <exception cref="ArgumentException">Invalid expander isentropic efficiency!</exception>
105+
IFluid ExpansionTo(Pressure pressure, Ratio isentropicEfficiency);
106+
107+
/// <summary>
108+
/// The process of cooling to given temperature.
109+
/// </summary>
110+
/// <param name="temperature">Temperature.</param>
111+
/// <param name="pressureDrop">Pressure drop in the heat exchanger (optional).</param>
112+
/// <returns>The state of the fluid at the end of the process.</returns>
113+
/// <exception cref="ArgumentException">
114+
/// During the cooling process, the temperature should decrease!
115+
/// </exception>
116+
/// <exception cref="ArgumentException">Invalid pressure drop in the heat exchanger!</exception>
117+
IFluid CoolingTo(Temperature temperature, Pressure? pressureDrop = null);
118+
119+
/// <summary>
120+
/// The process of cooling to given enthalpy.
121+
/// </summary>
122+
/// <param name="enthalpy">Enthalpy.</param>
123+
/// <param name="pressureDrop">Pressure drop in the heat exchanger (optional).</param>
124+
/// <returns>The state of the fluid at the end of the process.</returns>
125+
/// <exception cref="ArgumentException">
126+
/// During the cooling process, the enthalpy should decrease!
127+
/// </exception>
128+
/// <exception cref="ArgumentException">Invalid pressure drop in the heat exchanger!</exception>
129+
IFluid CoolingTo(SpecificEnergy enthalpy, Pressure? pressureDrop = null);
130+
131+
/// <summary>
132+
/// The process of heating to given temperature.
133+
/// </summary>
134+
/// <param name="temperature">Temperature.</param>
135+
/// <param name="pressureDrop">Pressure drop in the heat exchanger (optional).</param>
136+
/// <returns>The state of the fluid at the end of the process.</returns>
137+
/// <exception cref="ArgumentException">
138+
/// During the heating process, the temperature should increase!
139+
/// </exception>
140+
/// <exception cref="ArgumentException">Invalid pressure drop in the heat exchanger!</exception>
141+
IFluid HeatingTo(Temperature temperature, Pressure? pressureDrop = null);
142+
143+
/// <summary>
144+
/// The process of heating to given enthalpy.
145+
/// </summary>
146+
/// <param name="enthalpy">Enthalpy.</param>
147+
/// <param name="pressureDrop">Pressure drop in the heat exchanger (optional).</param>
148+
/// <returns>The state of the fluid at the end of the process.</returns>
149+
/// <exception cref="ArgumentException">
150+
/// During the heating process, the enthalpy should increase!
151+
/// </exception>
152+
/// <exception cref="ArgumentException">Invalid pressure drop in the heat exchanger!</exception>
153+
IFluid HeatingTo(SpecificEnergy enthalpy, Pressure? pressureDrop = null);
154+
155+
/// <summary>
156+
/// Returns a bubble point at given pressure.
157+
/// </summary>
158+
/// <param name="pressure">Pressure.</param>
159+
/// <returns>A bubble point at given pressure.</returns>
160+
IFluid BubblePointAt(Pressure pressure);
161+
162+
/// <summary>
163+
/// Returns a bubble point at given temperature.
164+
/// </summary>
165+
/// <param name="temperature">Temperature.</param>
166+
/// <returns>A bubble point at given temperature.</returns>
167+
IFluid BubblePointAt(Temperature temperature);
168+
169+
/// <summary>
170+
/// Returns a dew point at given pressure.
171+
/// </summary>
172+
/// <param name="pressure">Pressure.</param>
173+
/// <returns>A dew point at given pressure.</returns>
174+
IFluid DewPointAt(Pressure pressure);
175+
176+
/// <summary>
177+
/// Returns a dew point at given temperature.
178+
/// </summary>
179+
/// <param name="temperature">Temperature.</param>
180+
/// <returns>A dew point at given temperature.</returns>
181+
IFluid DewPointAt(Temperature temperature);
182+
183+
/// <summary>
184+
/// Returns a two-phase point at given pressure.
185+
/// </summary>
186+
/// <param name="pressure">Pressure.</param>
187+
/// <param name="quality">Vapor quality.</param>
188+
/// <returns>Two-phase point at given pressure.</returns>
189+
IFluid TwoPhasePointAt(Pressure pressure, Ratio quality);
190+
191+
/// <summary>
192+
/// The mixing process.
193+
/// </summary>
194+
/// <param name="firstSpecificMassFlow">
195+
/// Specific mass flow rate of the fluid at the first state.
196+
/// </param>
197+
/// <param name="first">Fluid at the first state.</param>
198+
/// <param name="secondSpecificMassFlow">
199+
/// Specific mass flow rate of the fluid at the second state.
200+
/// </param>
201+
/// <param name="second">Fluid at the second state.</param>
202+
/// <returns>The state of the fluid at the end of the process.</returns>
203+
/// <exception cref="ArgumentException">
204+
/// The mixing process is possible only for the same fluids!
205+
/// </exception>
206+
/// <exception cref="ArgumentException">
207+
/// The mixing process is possible only for flows with the same pressure!
208+
/// </exception>
209+
IFluid Mixing(
210+
Ratio firstSpecificMassFlow,
211+
IFluid first,
212+
Ratio secondSpecificMassFlow,
213+
IFluid second
214+
);
215+
}
216+
5217
/// <inheritdoc cref="IFluid"/>
6218
public class Fluid : AbstractFluid, IFluid
7219
{

src/SharpProp/Fluids/FluidState.cs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,148 @@
22

33
namespace SharpProp;
44

5+
/// <summary>
6+
/// Fluid state.
7+
/// </summary>
8+
public interface IFluidState
9+
{
10+
/// <summary>
11+
/// Compressibility factor (dimensionless).
12+
/// </summary>
13+
double? Compressibility { get; }
14+
15+
/// <summary>
16+
/// Thermal conductivity (by default, W/m/K).
17+
/// </summary>
18+
ThermalConductivity? Conductivity { get; }
19+
20+
/// <summary>
21+
/// Absolute pressure at the critical point (by default, kPa).
22+
/// </summary>
23+
Pressure? CriticalPressure { get; }
24+
25+
/// <summary>
26+
/// Temperature at the critical point (by default, °C).
27+
/// </summary>
28+
Temperature? CriticalTemperature { get; }
29+
30+
/// <summary>
31+
/// Mass density (by default, kg/m3).
32+
/// </summary>
33+
Density Density { get; }
34+
35+
/// <summary>
36+
/// Dynamic viscosity (by default, mPa*s).
37+
/// </summary>
38+
DynamicViscosity? DynamicViscosity { get; }
39+
40+
/// <summary>
41+
/// Mass specific enthalpy (by default, kJ/kg).
42+
/// </summary>
43+
SpecificEnergy Enthalpy { get; }
44+
45+
/// <summary>
46+
/// Mass specific entropy (by default, kJ/kg/K).
47+
/// </summary>
48+
SpecificEntropy Entropy { get; }
49+
50+
/// <summary>
51+
/// Temperature at the freezing point
52+
/// (for incompressible fluids) (by default, °C).
53+
/// </summary>
54+
Temperature? FreezingTemperature { get; }
55+
56+
/// <summary>
57+
/// Mass specific internal energy (by default, kJ/kg).
58+
/// </summary>
59+
SpecificEnergy InternalEnergy { get; }
60+
61+
/// <summary>
62+
/// Kinematic viscosity (by default, cSt).
63+
/// </summary>
64+
KinematicViscosity? KinematicViscosity { get; }
65+
66+
/// <summary>
67+
/// Maximum pressure limit (by default, kPa).
68+
/// </summary>
69+
Pressure? MaxPressure { get; }
70+
71+
/// <summary>
72+
/// Maximum temperature limit (by default, °C).
73+
/// </summary>
74+
Temperature MaxTemperature { get; }
75+
76+
/// <summary>
77+
/// Minimum pressure limit (by default, kPa).
78+
/// </summary>
79+
Pressure? MinPressure { get; }
80+
81+
/// <summary>
82+
/// Minimum temperature limit (by default, °C).
83+
/// </summary>
84+
Temperature MinTemperature { get; }
85+
86+
/// <summary>
87+
/// Molar mass (by default, g/mol).
88+
/// </summary>
89+
MolarMass? MolarMass { get; }
90+
91+
/// <summary>
92+
/// Phase state.
93+
/// </summary>
94+
Phases Phase { get; }
95+
96+
/// <summary>
97+
/// Prandtl number (dimensionless).
98+
/// </summary>
99+
double? Prandtl { get; }
100+
101+
/// <summary>
102+
/// Absolute pressure (by default, kPa).
103+
/// </summary>
104+
Pressure Pressure { get; }
105+
106+
/// <summary>
107+
/// Mass vapor quality (by default, %).
108+
/// </summary>
109+
Ratio? Quality { get; }
110+
111+
/// <summary>
112+
/// Sound speed (by default, m/s).
113+
/// </summary>
114+
Speed? SoundSpeed { get; }
115+
116+
/// <summary>
117+
/// Mass specific constant pressure specific heat (by default, kJ/kg/K).
118+
/// </summary>
119+
SpecificEntropy SpecificHeat { get; }
120+
121+
/// <summary>
122+
/// Mass specific volume (by default, m3/kg).
123+
/// </summary>
124+
SpecificVolume SpecificVolume { get; }
125+
126+
/// <summary>
127+
/// Surface tension (by default, N/m).
128+
/// </summary>
129+
ForcePerLength? SurfaceTension { get; }
130+
131+
/// <summary>
132+
/// Temperature (by default, °C).
133+
/// </summary>
134+
Temperature Temperature { get; }
135+
136+
/// <summary>
137+
/// Absolute pressure at the triple point (by default, kPa).
138+
/// </summary>
139+
Pressure? TriplePressure { get; }
140+
141+
/// <summary>
142+
/// Temperature at the triple point (by default, °C).
143+
/// </summary>
144+
Temperature? TripleTemperature { get; }
145+
}
146+
5147
public abstract partial class AbstractFluid
6148
{
7149
protected const double Tolerance = 1e-6;

0 commit comments

Comments
 (0)