diff --git a/SharpFluids/SharpFluids files/Fluid.cs b/SharpFluids/SharpFluids files/Fluid.cs index 9a64e1a..822ca54 100644 --- a/SharpFluids/SharpFluids files/Fluid.cs +++ b/SharpFluids/SharpFluids files/Fluid.cs @@ -168,7 +168,7 @@ protected virtual void UpdateFluidConstants() /// /// Updates the values of the after an update /// - protected virtual void UpdateValues() + public virtual void UpdateValues() { try { @@ -244,37 +244,6 @@ public virtual void SetLimitsToZero() } - /// - /// Copy all the values from to this - /// - /// to be copied from - public void Copy(Fluid other) - { - //Copying Refrigerant type - CopyType(other); - - this.Enthalpy = other.Enthalpy; - this.MassFlow = other.MassFlow; - this.Mass = other.Mass; - this.Pressure = other.Pressure; - this.Temperature = other.Temperature; - this.Entropy = other.Entropy; - this.Quality = other.Quality; - this.Density = other.Density; - this.Cp = other.Cp; - this.Cv = other.Cv; - this.CriticalPressure = other.CriticalPressure; - this.DynamicViscosity = other.DynamicViscosity; - this.Conductivity = other.Conductivity; - this.Prandtl = other.Prandtl; - this.SoundSpeed = other.SoundSpeed; - this.SurfaceTension = other.SurfaceTension; - this.FailState = other.FailState; - this.MolarMass = other.MolarMass; - this.Compressibility = other.Compressibility; - this.InternalEnergy = other.InternalEnergy; - } - /// /// Copy just the type of fluid from to this /// @@ -552,7 +521,7 @@ protected void CheckFractionLimits(double fraction) } - private void CheckBeforeUpdate() + public void CheckBeforeUpdate() { if (REF is null) SetNewMedia(Media); diff --git a/SharpFluids/SharpFluids files/FluidEnvelope.cs b/SharpFluids/SharpFluids files/FluidEnvelope.cs index 69a98d8..e1ae39b 100644 --- a/SharpFluids/SharpFluids files/FluidEnvelope.cs +++ b/SharpFluids/SharpFluids files/FluidEnvelope.cs @@ -46,13 +46,13 @@ public partial class Fluid for (Pressure i = CriticalPressure - Pressure.FromBars(1); i > LimitPressureMin; i -= Increment) { - UpdatePX(i, 0); + this.UpdatePX(i, 0); if (!FailState) localListLiq.Add((i, Enthalpy)); - UpdatePX(i, 1); + this.UpdatePX(i, 1); if (!FailState) localListGas.Add((i, Enthalpy)); diff --git a/SharpFluids/SharpFluids files/FluidExtensions.cs b/SharpFluids/SharpFluids files/FluidExtensions.cs index 9e65e58..8619be1 100644 --- a/SharpFluids/SharpFluids files/FluidExtensions.cs +++ b/SharpFluids/SharpFluids files/FluidExtensions.cs @@ -130,5 +130,38 @@ public static Fluid RemovePower(this Fluid local, Power powerToBeRemoved) local.AddPower(powerToBeRemoved * -1); return local; } + + /// + /// Copy all the values from to this + /// + /// to be copied from + public static Fluid Copy(this Fluid local, Fluid other) + { + //Copying Refrigerant type + local.CopyType(other); + + local.Enthalpy = other.Enthalpy; + local.MassFlow = other.MassFlow; + local.Mass = other.Mass; + local.Pressure = other.Pressure; + local.Temperature = other.Temperature; + local.Entropy = other.Entropy; + local.Quality = other.Quality; + local.Density = other.Density; + local.Cp = other.Cp; + local.Cv = other.Cv; + local.CriticalPressure = other.CriticalPressure; + local.DynamicViscosity = other.DynamicViscosity; + local.Conductivity = other.Conductivity; + local.Prandtl = other.Prandtl; + local.SoundSpeed = other.SoundSpeed; + local.SurfaceTension = other.SurfaceTension; + local.FailState = other.FailState; + local.MolarMass = other.MolarMass; + local.Compressibility = other.Compressibility; + local.InternalEnergy = other.InternalEnergy; + return local; + } + } } diff --git a/SharpFluids/SharpFluids files/FluidProperties .cs b/SharpFluids/SharpFluids files/FluidProperties .cs index 645bbb4..0d9468e 100644 --- a/SharpFluids/SharpFluids files/FluidProperties .cs +++ b/SharpFluids/SharpFluids files/FluidProperties .cs @@ -64,7 +64,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "D", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public Density Density { get; protected set; } + public Density Density { get; set; } /// @@ -72,7 +72,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "DV", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public DynamicViscosity DynamicViscosity { get; protected set; } + public DynamicViscosity DynamicViscosity { get; set; } /// /// Get the of the . @@ -80,7 +80,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "C", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public ThermalConductivity Conductivity { get; protected set; } + public ThermalConductivity Conductivity { get; set; } /// /// Get the Cp of the . @@ -88,7 +88,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "Cp", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public SpecificEntropy Cp { get; protected set; } + public SpecificEntropy Cp { get; set; } /// /// Get the Cv of the . @@ -96,14 +96,14 @@ public partial class Fluid /// [JsonProperty(PropertyName = "Cv", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public SpecificEntropy Cv { get; protected set; } + public SpecificEntropy Cv { get; set; } /// /// Get the of Sound of the . /// [JsonProperty(PropertyName = "SS", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public Speed SoundSpeed { get; protected set; } + public Speed SoundSpeed { get; set; } /// /// Get the Surface Tension of the . @@ -111,21 +111,21 @@ public partial class Fluid /// [JsonProperty(PropertyName = "ST", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public ForcePerLength SurfaceTension { get; protected set; } + public ForcePerLength SurfaceTension { get; set; } /// /// Get the of the . /// [JsonProperty(PropertyName = "MM", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public MolarMass MolarMass { get; protected set; } + public MolarMass MolarMass { get; set; } /// /// Get the Internal Energy of the . /// [JsonProperty(PropertyName = "IE", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public SpecificEnergy InternalEnergy { get; protected set; } + public SpecificEnergy InternalEnergy { get; set; } /// /// Get the Prandtl number of the . @@ -134,7 +134,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "Pl", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public double Prandtl { get; protected set; } + public double Prandtl { get; set; } /// /// Get the Compressibility of the . @@ -143,7 +143,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "Co", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public double Compressibility { get; protected set; } + public double Compressibility { get; set; } /// /// Get the Quality of the . @@ -154,7 +154,7 @@ public partial class Fluid /// [JsonProperty(PropertyName = "Q", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public double Quality { get; protected set; } + public double Quality { get; set; } @@ -373,7 +373,7 @@ public VolumeFlow VolumeFlow /// [JsonProperty(PropertyName = "CP", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] //[JsonProperty] - public Pressure CriticalPressure { get; protected set; } + public Pressure CriticalPressure { get; set; } /// /// This library's minimum for the selected . @@ -413,7 +413,8 @@ public VolumeFlow VolumeFlow /// /// Used to access the CoolProp DLL. /// - protected AbstractState REF; + [JsonIgnore] + public AbstractState REF; /// diff --git a/SharpFluids/SharpFluids files/FluidUpdates.cs b/SharpFluids/SharpFluids files/FluidUpdates.cs index 4affbe7..559e289 100644 --- a/SharpFluids/SharpFluids files/FluidUpdates.cs +++ b/SharpFluids/SharpFluids files/FluidUpdates.cs @@ -10,7 +10,7 @@ namespace SharpFluids { - public partial class Fluid + public static class FluidUpdates { /// @@ -21,16 +21,16 @@ public partial class Fluid /// /// The used in the update /// The used in the update - public void UpdateDS(Density density, SpecificEntropy entropy) + public static Fluid UpdateDS(this Fluid local, Density density, SpecificEntropy entropy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } @@ -38,31 +38,31 @@ public void UpdateDS(Density density, SpecificEntropy entropy) if (density <= Density.Zero || entropy <= SpecificEntropy.Zero) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDS -> {density} cant be below {Density.Zero} and {entropy} cant be below {SpecificEntropy.Zero}"); - return; + return local; } try { - REF.update(input_pairs.DmassSmass_INPUTS, density.KilogramsPerCubicMeter, entropy.JoulesPerKilogramKelvin); - UpdateValues(); + local.REF.update(input_pairs.DmassSmass_INPUTS, density.KilogramsPerCubicMeter, entropy.JoulesPerKilogramKelvin); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDS -> CoolProp could not return your request on {density} and {entropy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateDS -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {density} and {entropy} {e}"); throw; } - + return local; } @@ -75,17 +75,17 @@ public void UpdateDS(Density density, SpecificEntropy entropy) /// /// The used in the update /// The used in the update - public void UpdateDP(Density density, Pressure pressure) + public static Fluid UpdateDP(this Fluid local, Density density, Pressure pressure) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } @@ -93,33 +93,33 @@ public void UpdateDP(Density density, Pressure pressure) if (density <= Density.Zero || pressure <= Pressure.Zero) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDP -> {density} cant be below {Density.Zero} and {pressure} cant be below {Pressure.Zero}"); - return; + return local; } - if (pressure > LimitPressureMax) - Log.Debug($"SharpFluid -> UpdateDP -> {pressure} is above 'LimitPressureMax' ({LimitPressureMax}) - This result is extrapolated hence precision is decreased"); + if (pressure > local.LimitPressureMax) + Log.Debug($"SharpFluid -> UpdateDP -> {pressure} is above 'LimitPressureMax' ({local.LimitPressureMax}) - This result is extrapolated hence precision is decreased"); try { - REF.update(input_pairs.DmassP_INPUTS, density.KilogramsPerCubicMeter, pressure.Pascals); - UpdateValues(); + local.REF.update(input_pairs.DmassP_INPUTS, density.KilogramsPerCubicMeter, pressure.Pascals); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDP -> CoolProp could not return your request on {density} and {pressure} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateDP -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {density} and {pressure} {e}"); throw; } - + return local; } @@ -131,49 +131,49 @@ public void UpdateDP(Density density, Pressure pressure) /// /// The used in the update /// The used in the update - public void UpdateDT(Density density, Temperature temperature) + public static Fluid UpdateDT(this Fluid local, Density density, Temperature temperature) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } - if (density <= Density.Zero || temperature < LimitTemperatureMin) + if (density <= Density.Zero || temperature < local.LimitTemperatureMin) { - FailState = true; - Log.Debug($"SharpFluid -> UpdateDT -> {density} cant be below {Density.Zero} and {temperature} cant be below {LimitTemperatureMin}"); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdateDT -> {density} cant be below {Density.Zero} and {temperature} cant be below {local.LimitTemperatureMin}"); + return local; } - if (temperature > LimitTemperatureMax) - Log.Debug($"SharpFluid -> UpdateDT -> {temperature} is above 'LimitTemperatureMax' ({LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); + if (temperature > local.LimitTemperatureMax) + Log.Debug($"SharpFluid -> UpdateDT -> {temperature} is above 'LimitTemperatureMax' ({local.LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); try { - REF.update(input_pairs.DmassT_INPUTS, density.KilogramsPerCubicMeter, temperature.Kelvins); - UpdateValues(); + local.REF.update(input_pairs.DmassT_INPUTS, density.KilogramsPerCubicMeter, temperature.Kelvins); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDT -> CoolProp could not return your request on {density} and {temperature} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateDT -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {density} and {temperature} {e}"); throw; } - + return local; } @@ -186,46 +186,47 @@ public void UpdateDT(Density density, Temperature temperature) /// /// The used in the update /// The Enthalpy used in the update - public void UpdateDH(Density density, SpecificEnergy enthalpy) + public static Fluid UpdateDH(this Fluid local, Density density, SpecificEnergy enthalpy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } if (density <= Density.Zero) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDH -> {density} cant be below {Density.Zero} and {enthalpy} cant be below (limit unknown)"); - return; + return local; } try { - REF.update(input_pairs.DmassHmass_INPUTS, density.KilogramsPerCubicMeter, enthalpy.JoulesPerKilogram); - UpdateValues(); + local.REF.update(input_pairs.DmassHmass_INPUTS, density.KilogramsPerCubicMeter, enthalpy.JoulesPerKilogram); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateDH -> CoolProp could not return your request on {density} and {enthalpy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateDH -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {density} and {enthalpy} {e}"); throw; } + return local; } @@ -237,52 +238,53 @@ public void UpdateDH(Density density, SpecificEnergy enthalpy) /// /// The used in the update /// The used in the update - public void UpdatePT(Pressure pressure, Temperature temperature) + public static Fluid UpdatePT(this Fluid local, Pressure pressure, Temperature temperature) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { - UpdateCustomFluid(temperature, pressure); - return; + local.UpdateCustomFluid(temperature, pressure); + return local; } - if (pressure < LimitPressureMin || temperature < LimitTemperatureMin) + if (pressure < local.LimitPressureMin || temperature < local.LimitTemperatureMin) { - FailState = true; - Log.Debug($"SharpFluid -> UpdatePT -> {pressure} cant be below {LimitPressureMin} and {temperature} cant be below {LimitTemperatureMin}"); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdatePT -> {pressure} cant be below {local.LimitPressureMin} and {temperature} cant be below {local.LimitTemperatureMin}"); + return local; } - if (temperature > LimitTemperatureMax) - Log.Debug($"SharpFluid -> UpdatePT -> {temperature} is above 'LimitTemperatureMax' ({LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); + if (temperature > local.LimitTemperatureMax) + Log.Debug($"SharpFluid -> UpdatePT -> {temperature} is above 'LimitTemperatureMax' ({local.LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); - if (pressure > LimitPressureMax) - Log.Debug($"SharpFluid -> UpdatePT -> {pressure} is above 'LimitPressureMax' ({LimitPressureMax}) - This result is extrapolated hence precision is decreased"); + if (pressure > local.LimitPressureMax) + Log.Debug($"SharpFluid -> UpdatePT -> {pressure} is above 'LimitPressureMax' ({local.LimitPressureMax}) - This result is extrapolated hence precision is decreased"); try { - REF.update(input_pairs.PT_INPUTS, pressure.Pascals, temperature.Kelvins); - UpdateValues(); + local.REF.update(input_pairs.PT_INPUTS, pressure.Pascals, temperature.Kelvins); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdatePT -> CoolProp could not return your request on {pressure} and {temperature} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdatePT -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {pressure} and {temperature} {e}"); throw; } + return local; } @@ -294,55 +296,57 @@ public void UpdatePT(Pressure pressure, Temperature temperature) /// /// The Quality used in the update /// The used in the update - public void UpdateXT(double quality, Temperature temperature) + public static Fluid UpdateXT(this Fluid local, double quality, Temperature temperature) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (temperature < LimitTemperatureMin) + if (temperature < local.LimitTemperatureMin) { - FailState = true; - Log.Debug($"SharpFluid -> UpdateXT -> {temperature} cant be below {LimitTemperatureMin}", temperature, LimitTemperatureMin); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdateXT -> {temperature} cant be below {local.LimitTemperatureMin}", temperature, local.LimitTemperatureMin); + return local; } - if (temperature > LimitTemperatureMax) - Log.Debug($"SharpFluid -> UpdateXT -> {temperature} is above 'LimitTemperatureMax' ({LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); + if (temperature > local.LimitTemperatureMax) + Log.Debug($"SharpFluid -> UpdateXT -> {temperature} is above 'LimitTemperatureMax' ({local.LimitTemperatureMax}) - This result is extrapolated hence precision is decreased"); try { //If we are above transcritical we just return the Critical point - if (temperature >= CriticalTemperature) + if (temperature >= local.CriticalTemperature) { - Log.Debug($"SharpFluid -> UpdateXT -> {temperature} is above CriticalTemperature ({CriticalTemperature}) -> We will just return you the CriticalTemperature!"); - REF.update(input_pairs.QT_INPUTS, quality, CriticalTemperature.Kelvins); + Log.Debug($"SharpFluid -> UpdateXT -> {temperature} is above CriticalTemperature ({local.CriticalTemperature}) -> We will just return you the CriticalTemperature!"); + local.REF.update(input_pairs.QT_INPUTS, quality, local.CriticalTemperature.Kelvins); } else { - REF.update(input_pairs.QT_INPUTS, quality, temperature.Kelvins); + local.REF.update(input_pairs.QT_INPUTS, quality, temperature.Kelvins); } - UpdateValues(); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateXT -> CoolProp could not return your request on {quality} and {temperature} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateXT -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {quality} and {temperature} {e}"); throw; } + return local; + } @@ -352,12 +356,12 @@ public void UpdateXT(double quality, Temperature temperature) /// /// /// The Enthalpy used in the update /// The used in the update - public void UpdateHT(SpecificEnergy enthalpy, Temperature temperature) + public static Fluid UpdateHT(this Fluid local, SpecificEnergy enthalpy, Temperature temperature) { //Not yet supported by CoolProp! Log.Debug($"SharpFluid -> UpdateHT -> Not yet supported by CoolProp!"); throw new NotImplementedException($"SharpFluid -> UpdateHT -> Not (yet) supported by CoolProp!"); - REF.update(input_pairs.HmassT_INPUTS, enthalpy.JoulesPerKilogram, temperature.Kelvins); + local.REF.update(input_pairs.HmassT_INPUTS, enthalpy.JoulesPerKilogram, temperature.Kelvins); } @@ -369,48 +373,49 @@ public void UpdateHT(SpecificEnergy enthalpy, Temperature temperature) /// /// The used in the update /// The used in the update - public void UpdatePS(Pressure pressure, SpecificEntropy entropy) + public static Fluid UpdatePS(this Fluid local, Pressure pressure, SpecificEntropy entropy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } - if (pressure < LimitPressureMin) + if (pressure < local.LimitPressureMin) { - FailState = true; - Log.Debug($"SharpFluid -> UpdatePS -> {pressure} cant be below {LimitPressureMin} and {entropy} cant be below (limit unknown)"); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdatePS -> {pressure} cant be below {local.LimitPressureMin} and {entropy} cant be below (limit unknown)"); + return local; } - if (pressure > LimitPressureMax) - Log.Debug($"SharpFluid -> UpdatePS -> {pressure} is above 'LimitPressureMax' ({LimitPressureMax}) - This result is extrapolated hence precision is decreased"); + if (pressure > local.LimitPressureMax) + Log.Debug($"SharpFluid -> UpdatePS -> {pressure} is above 'LimitPressureMax' ({local.LimitPressureMax}) - This result is extrapolated hence precision is decreased"); try { - REF.update(input_pairs.PSmass_INPUTS, pressure.Pascals, entropy.JoulesPerKilogramKelvin); - UpdateValues(); + local.REF.update(input_pairs.PSmass_INPUTS, pressure.Pascals, entropy.JoulesPerKilogramKelvin); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdatePS -> CoolProp could not return your request on {pressure} and {entropy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdatePS -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {pressure} and {entropy} {e}"); throw; } + return local; } @@ -423,49 +428,50 @@ public void UpdatePS(Pressure pressure, SpecificEntropy entropy) /// /// The used in the update /// The Enthalpy used in the update - public void UpdatePH(Pressure pressure, SpecificEnergy enthalpy) + public static Fluid UpdatePH(this Fluid local, Pressure pressure, SpecificEnergy enthalpy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } - if (pressure < LimitPressureMin || enthalpy <= SpecificEnergy.Zero) + if (pressure < local.LimitPressureMin || enthalpy <= SpecificEnergy.Zero) { - FailState = true; - Log.Debug($"SharpFluid -> UpdatePH -> {pressure} cant be below {LimitPressureMin} and {enthalpy} cant be below {SpecificEnergy.Zero}"); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdatePH -> {pressure} cant be below {local.LimitPressureMin} and {enthalpy} cant be below {SpecificEnergy.Zero}"); + return local; } - if (pressure > LimitPressureMax) - Log.Debug($"SharpFluid -> UpdatePH -> {pressure} is above 'LimitPressureMax' ({LimitPressureMax}) - This result is extrapolated hence precision is decreased"); + if (pressure > local.LimitPressureMax) + Log.Debug($"SharpFluid -> UpdatePH -> {pressure} is above 'LimitPressureMax' ({local.LimitPressureMax}) - This result is extrapolated hence precision is decreased"); try { - REF.update(input_pairs.HmassP_INPUTS, enthalpy.JoulesPerKilogram, pressure.Pascals); - UpdateValues(); + local.REF.update(input_pairs.HmassP_INPUTS, enthalpy.JoulesPerKilogram, pressure.Pascals); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdatePH -> CoolProp could not return your request on {pressure} and {enthalpy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdatePH -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {pressure} and {enthalpy} {e}"); throw; } + return local; } /// @@ -476,56 +482,57 @@ public void UpdatePH(Pressure pressure, SpecificEnergy enthalpy) /// /// The used in the update /// The Quality used in the update - public void UpdatePX(Pressure pressure, double quality) + public static Fluid UpdatePX(this Fluid local, Pressure pressure, double quality) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (pressure < LimitPressureMin || quality < 0) + if (pressure < local.LimitPressureMin || quality < 0) { - FailState = true; - Log.Debug($"SharpFluid -> UpdatePX -> {pressure} cant be bolow {LimitPressureMin}", pressure, LimitPressureMin); - return; + local.FailState = true; + Log.Debug($"SharpFluid -> UpdatePX -> {pressure} cant be bolow {local.LimitPressureMin}", pressure, local.LimitPressureMin); + return local; } - if (pressure > LimitPressureMax) - Log.Debug($"SharpFluid -> UpdatePX -> {pressure} is above 'LimitPressureMax' ({LimitPressureMax}) - This result is extrapolated hence precision is decreased"); + if (pressure > local.LimitPressureMax) + Log.Debug($"SharpFluid -> UpdatePX -> {pressure} is above 'LimitPressureMax' ({local.LimitPressureMax}) - This result is extrapolated hence precision is decreased"); try { - if (pressure > CriticalPressure) + if (pressure > local.CriticalPressure) { - UpdatePT(CriticalPressure, CriticalTemperature); - UpdatePH(pressure, Enthalpy); - Log.Debug($"SharpFluid -> UpdatePX -> {pressure} is above CriticalPressure ({CriticalPressure}) -> We will just return you the Critical point!"); + local.UpdatePT(local.CriticalPressure, local.CriticalTemperature); + local.UpdatePH(pressure, local.Enthalpy); + Log.Debug($"SharpFluid -> UpdatePX -> {pressure} is above CriticalPressure ({local.CriticalPressure}) -> We will just return you the Critical point!"); - if (FailState) + if (local.FailState) { - SetValuesToZero(); + local.SetValuesToZero(); } } else { - REF.update(input_pairs.PQ_INPUTS, pressure.Pascals, quality); - UpdateValues(); + local.REF.update(input_pairs.PQ_INPUTS, pressure.Pascals, quality); + local.UpdateValues(); } } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdatePX -> CoolProp could not return your request on {pressure} and {quality} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdatePX -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {pressure} and {quality} {e}"); throw; } + return local; } @@ -540,36 +547,37 @@ public void UpdatePX(Pressure pressure, double quality) /// /// The Enthalpy used in the update /// The used in the update - public void UpdateHS(SpecificEnergy enthalpy, SpecificEntropy entropy) + public static Fluid UpdateHS(this Fluid local, SpecificEnergy enthalpy, SpecificEntropy entropy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } try { - REF.update(input_pairs.HmassSmass_INPUTS, enthalpy.JoulesPerKilogram, entropy.JoulesPerKilogramKelvin); - UpdateValues(); + local.REF.update(input_pairs.HmassSmass_INPUTS, enthalpy.JoulesPerKilogram, entropy.JoulesPerKilogramKelvin); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateHS -> CoolProp could not return your request on {enthalpy} and {entropy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateHS -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {enthalpy} and {entropy} {e}"); throw; } + return local; } /// @@ -580,36 +588,38 @@ public void UpdateHS(SpecificEnergy enthalpy, SpecificEntropy entropy) /// /// The Temperature used in the update /// The used in the update - public void UpdateTS(Temperature temperature, SpecificEntropy entropy) + public static Fluid UpdateTS(this Fluid local, Temperature temperature, SpecificEntropy entropy) { - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType == "CustomFluid") + if (local.Media.BackendType == "CustomFluid") { throw new NotImplementedException("CustomFluid only works with UpdatePT()"); } - if (Media.InternalName.Contains(".mix")) + if (local.Media.InternalName.Contains(".mix")) { throw new NotImplementedException("For mixtures only UpdatePX, UpdateXT and UpdatePT works"); } try { - REF.update(input_pairs.SmassT_INPUTS, entropy.JoulesPerKilogramKelvin, temperature.Kelvins); - UpdateValues(); + local.REF.update(input_pairs.SmassT_INPUTS, entropy.JoulesPerKilogramKelvin, temperature.Kelvins); + local.UpdateValues(); } catch (System.ApplicationException e) { - FailState = true; + local.FailState = true; Log.Debug($"SharpFluid -> UpdateHS -> CoolProp could not return your request on {temperature} and {entropy} and returns the followering error: {e}"); } catch (System.Exception e) { - FailState = true; + local.FailState = true; Log.Error($"SharpFluid -> UpdateHS -> Report this on https://github.com/MadsKirkFoged/SharpFluids - CoolProp returned unexpected result! {temperature} and {entropy} {e}"); throw; } + + return local; } /// @@ -619,57 +629,57 @@ public void UpdateTS(Temperature temperature, SpecificEntropy entropy) ///
Water.UpdateCustomFluid(.FromKelvins(286.15));
///
/// The Temperature used in the update - private void UpdateCustomFluid(Temperature temperature, Pressure pressure) + private static Fluid UpdateCustomFluid(this Fluid local, Temperature temperature, Pressure pressure) { //THIS IS IN BETA MODE - CheckBeforeUpdate(); + local.CheckBeforeUpdate(); - if (Media.BackendType != "CustomFluid") + if (local.Media.BackendType != "CustomFluid") { throw new NotImplementedException("This is in Beta and only works with CustomFluids!"); } - CustomOil Above = GetCustomFluidFromDatabase().FindAll(x => x.Temperature >= temperature).OrderBy(p => p.Temperature).First(); - CustomOil Below = GetCustomFluidFromDatabase().FindAll(x => x.Temperature <= temperature).OrderByDescending(p => p.Temperature).First(); - + CustomOil Above = local.GetCustomFluidFromDatabase().FindAll(x => x.Temperature >= temperature).OrderBy(p => p.Temperature).First(); + CustomOil Below = local.GetCustomFluidFromDatabase().FindAll(x => x.Temperature <= temperature).OrderByDescending(p => p.Temperature).First(); - Temperature = temperature; - Pressure = pressure; + local.Temperature = temperature; + local.Pressure = pressure; - Density = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.Density, Above.Density); + local.Density = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.Density, Above.Density); - Cp = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.Cp, Above.Cp); - Conductivity = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.ThermalConductivity, Above.ThermalConductivity); + local.Cp = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.Cp, Above.Cp); - DynamicViscosity = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.KinematicViscosity, Above.KinematicViscosity) * Density; + local.Conductivity = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.ThermalConductivity, Above.ThermalConductivity); + local.DynamicViscosity = UnitMath.LinearInterpolation(temperature, Below.Temperature, Above.Temperature, Below.KinematicViscosity, Above.KinematicViscosity) * local.Density; + return local; } - public List GetCustomFluidFromDatabase() + public static List GetCustomFluidFromDatabase(this Fluid local) { - if (Media.InternalName == "SHC226E") + if (local.Media.InternalName == "SHC226E") { return SHC226E.GetList(); } - if (Media.InternalName == "SHC228") + if (local.Media.InternalName == "SHC228") { return SHC228.GetList(); } - if (Media.InternalName == "SHC230") + if (local.Media.InternalName == "SHC230") { return SHC230.GetList(); } @@ -680,7 +690,7 @@ public List GetCustomFluidFromDatabase() } - + } }