Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
portyanikhin committed Aug 29, 2024
1 parent 5d389a7 commit 794dae0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/VCRC/Abstract/ITwoStageVCRC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public interface ITwoStageVCRC : IVCRC
/// <summary>
/// Absolute intermediate pressure.
/// </summary>
public Pressure IntermediatePressure { get; }
Pressure IntermediatePressure { get; }

/// <summary>
/// Specific mass flow rate of the intermediate circuit.
/// </summary>
public Ratio IntermediateSpecificMassFlow { get; }
Ratio IntermediateSpecificMassFlow { get; }
}
28 changes: 14 additions & 14 deletions src/VCRC/Abstract/IVCRC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,70 @@ public interface IVCRC : IEntropyAnalysable
/// <summary>
/// Evaporator.
/// </summary>
public IEvaporator Evaporator { get; }
IEvaporator Evaporator { get; }

/// <summary>
/// Compressor.
/// </summary>
public ICompressor Compressor { get; }
ICompressor Compressor { get; }

/// <summary>
/// Heat releaser (condenser for subcritical VCRC or gas cooler for transcritical VCRC).
/// </summary>
public IHeatReleaser HeatReleaser { get; }
IHeatReleaser HeatReleaser { get; }

/// <summary>
/// Condenser (not <c>null</c> for subcritical VCRC).
/// </summary>
public ICondenser? Condenser { get; }
ICondenser? Condenser { get; }

/// <summary>
/// Gas cooler (not <c>null</c> for transcritical VCRC).
/// </summary>
public IHeatReleaser? GasCooler { get; }
IHeatReleaser? GasCooler { get; }

/// <summary>
/// <c>true</c> if VCRC is transcritical, <c>false</c> if VCRC is subcritical.
/// </summary>
public bool IsTranscritical { get; }
bool IsTranscritical { get; }

/// <summary>
/// Specific mass flow rate of the evaporator.
/// </summary>
public Ratio EvaporatorSpecificMassFlow { get; }
Ratio EvaporatorSpecificMassFlow { get; }

/// <summary>
/// Specific mass flow rate of the condenser or gas cooler.
/// </summary>
public Ratio HeatReleaserSpecificMassFlow { get; }
Ratio HeatReleaserSpecificMassFlow { get; }

/// <summary>
/// Specific work of isentropic compression.
/// </summary>
public SpecificEnergy IsentropicSpecificWork { get; }
SpecificEnergy IsentropicSpecificWork { get; }

/// <summary>
/// Specific work of real compression.
/// </summary>
public SpecificEnergy SpecificWork { get; }
SpecificEnergy SpecificWork { get; }

/// <summary>
/// Specific cooling capacity of the cycle.
/// </summary>
public SpecificEnergy SpecificCoolingCapacity { get; }
SpecificEnergy SpecificCoolingCapacity { get; }

/// <summary>
/// Specific heating capacity of the cycle.
/// </summary>
public SpecificEnergy SpecificHeatingCapacity { get; }
SpecificEnergy SpecificHeatingCapacity { get; }

/// <summary>
/// Energy efficiency ratio, aka cooling coefficient.
/// </summary>
public double EER { get; }
double EER { get; }

/// <summary>
/// Coefficient of performance, aka heating coefficient.
/// </summary>
public double COP { get; }
double COP { get; }
}
65 changes: 36 additions & 29 deletions src/VCRC/EntropyAnalysis/EntropyAnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,48 @@ public static class EntropyAnalysisExtensions
/// <summary>
/// Performs VCRC entropy analysis over a range of indoor and outdoor temperatures.
/// </summary>
/// <param name="cycles">List of VCRCs.</param>
/// <param name="indoor">List of indoor temperatures.</param>
/// <param name="outdoor">List of outdoor temperatures.</param>
/// <param name="cycles">Enumerable of VCRCs.</param>
/// <param name="indoor">Enumerable of indoor temperatures.</param>
/// <param name="outdoor">Enumerable of outdoor temperatures.</param>
/// <returns>Result of the VCRC entropy analysis in range of temperatures.</returns>
/// <exception cref="ArgumentException">The lists should have the same length!</exception>
/// <exception cref="ArgumentException">Inputs should have the same length!</exception>
public static IEntropyAnalysisResult EntropyAnalysis(
this IList<IEntropyAnalysable> cycles,
IList<Temperature> indoor,
IList<Temperature> outdoor
) =>
cycles.Count == indoor.Count && indoor.Count == outdoor.Count
? cycles
.Select((cycle, i) => cycle.EntropyAnalysis(indoor[i], outdoor[i]))
.ToList()
this IEnumerable<IEntropyAnalysable> cycles,
IEnumerable<Temperature> indoor,
IEnumerable<Temperature> outdoor
)
{
var cyclesList = cycles.ToList();
var indoorList = indoor.ToList();
var outdoorList = outdoor.ToList();
return cyclesList.Count == indoorList.Count && indoorList.Count == outdoorList.Count
? cyclesList
.Select((cycle, i) => cycle.EntropyAnalysis(indoorList[i], outdoorList[i]))
.Average()
: throw new ArgumentException("The lists should have the same length!");
: throw new ArgumentException("Inputs should have the same length!");
}

/// <summary>
/// Computes the average of a list of the entropy analysis results.
/// Computes the average of the entropy analysis results.
/// </summary>
/// <param name="results">List of the entropy analysis results.</param>
/// <param name="results">Enumerable of the entropy analysis results.</param>
/// <returns>The average.</returns>
public static IEntropyAnalysisResult Average(this IList<IEntropyAnalysisResult> results) =>
new EntropyAnalysisResult(
results.Select(i => i.ThermodynamicPerfection.Percent).Average().Percent(),
results.Select(i => i.MinSpecificWorkRatio.Percent).Average().Percent(),
results.Select(i => i.CompressorEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.CondenserEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.GasCoolerEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.ExpansionValvesEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.EjectorEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.EvaporatorEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.RecuperatorEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.EconomizerEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.MixingEnergyLossRatio.Percent).Average().Percent(),
results.Select(i => i.AnalysisRelativeError.Percent).Average().Percent()
public static IEntropyAnalysisResult Average(this IEnumerable<IEntropyAnalysisResult> results)
{
var resultsList = results.ToList();
return new EntropyAnalysisResult(
resultsList.Select(i => i.ThermodynamicPerfection.Percent).Average().Percent(),
resultsList.Select(i => i.MinSpecificWorkRatio.Percent).Average().Percent(),
resultsList.Select(i => i.CompressorEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.CondenserEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.GasCoolerEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.ExpansionValvesEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.EjectorEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.EvaporatorEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.RecuperatorEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.EconomizerEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.MixingEnergyLossRatio.Percent).Average().Percent(),
resultsList.Select(i => i.AnalysisRelativeError.Percent).Average().Percent()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void EntropyAnalysisInRange_ListsOfTemperaturesWithDifferentCount_ThrowsA
action
.Should()
.Throw<ArgumentException>()
.WithMessage("The lists should have the same length!");
.WithMessage("Inputs should have the same length!");
}

[Fact]
Expand Down

0 comments on commit 794dae0

Please sign in to comment.