Skip to content

Commit

Permalink
first version flow efficiency (#1209)
Browse files Browse the repository at this point in the history
* first version flow efficiency

* update
  • Loading branch information
EvenSol authored Dec 10, 2024
1 parent 5f2520b commit d1007e2
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public class CompressorChart implements CompressorChartInterface, java.io.Serial
PolynomialFunction fanLawCorrectionFunc = null;
double[] speed;
double[][] flow;
double[][] flowPolytropicEfficiency;
double[][] head;
double[][] polytropicEfficiency;
double[][] redflow;
double[][] redflowPolytropicEfficiency;
double[][] redhead;
double[][] redpolytropicEfficiency;

Expand All @@ -62,7 +64,16 @@ public CompressorChart() {}
/** {@inheritDoc} */
@Override
public void addCurve(double speed, double[] flow, double[] head, double[] polytropicEfficiency) {
CompressorCurve curve = new CompressorCurve(speed, flow, head, polytropicEfficiency);
CompressorCurve curve = new CompressorCurve(speed, flow, head, flow, polytropicEfficiency);
chartValues.add(curve);
}

/** {@inheritDoc} */
@Override
public void addCurve(double speed, double[] flow, double[] head,
double[] flowPolytropicEfficiency, double[] polytropicEfficiency) {
CompressorCurve curve =
new CompressorCurve(speed, flow, head, flowPolytropicEfficiency, polytropicEfficiency);
chartValues.add(curve);
}

Expand All @@ -80,21 +91,48 @@ public void addCurve(double speed, double[] flow, double[] head, double[] polytr
@Override
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] polyEff) {
this.setCurves(chartConditions, speed, flow, head, flow, polyEff);
}

/**
* {@inheritDoc}
*
* This method initializes the compressor performance curves, including speed, flow, head, and
* polytropic efficiency.
*
* <p>
* The method takes chart conditions and initializes internal variables for different performance
* parameters based on input arrays for speed, flow, head, and polytropic efficiency. It also
* normalizes these parameters by calculating reduced values based on speed.
*/
@Override
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] flowPolyEff, double[][] polyEff) {
this.speed = speed;
this.head = head;
this.polytropicEfficiency = polyEff;
this.flow = flow;
this.flowPolytropicEfficiency = flowPolyEff;

// Dynamically initialize arrays based on the maximum length of flow, head, and polyEff
int maxLength = 0;
for (double[] f : flow) {
if (f.length > maxLength)
if (f.length > maxLength) {
maxLength = f.length;
}
}

int maxLengthPolyEff = 0;
for (double[] f : flowPolytropicEfficiency) {
if (f.length > maxLengthPolyEff) {
maxLengthPolyEff = f.length;
}
}

this.redhead = new double[head.length][maxLength];
this.redpolytropicEfficiency = new double[polyEff.length][maxLength];
this.redflow = new double[flow.length][maxLength];
this.redflowPolytropicEfficiency = new double[polyEff.length][maxLength];

for (int i = 0; i < speed.length; i++) {
if (speed[i] > maxSpeedCurve) {
Expand All @@ -103,25 +141,31 @@ public void setCurves(double[] chartConditions, double[] speed, double[][] flow,
if (speed[i] < minSpeedCurve) {
minSpeedCurve = speed[i];
}
CompressorCurve curve = new CompressorCurve(speed[i], flow[i], head[i], polyEff[i]);
CompressorCurve curve =
new CompressorCurve(speed[i], flow[i], head[i], flowPolyEff[i], polyEff[i]);
chartValues.add(curve);

for (int j = 0; j < flow[i].length; j++) { // Handle differing lengths for each speed
redflow[i][j] = flow[i][j] / speed[i];
redpolytropicEfficiency[i][j] = polyEff[i][j];
redhead[i][j] = head[i][j] / speed[i] / speed[i];
reducedHeadFitter.add(redflow[i][j], redhead[i][j]);
reducedPolytropicEfficiencyFitter.add(redflow[i][j], redpolytropicEfficiency[i][j]);
double flowFanLaw = flow[i][j] * speed[i] / speed[0];
// TODO: MLLU: not correct. speed[0] should be the requested speed
fanLawCorrectionFitter.add(speed[i] / speed[0], flow[i][j] / flowFanLaw);
}

for (int j = 0; j < flowPolytropicEfficiency[i].length; j++) { // Handle differing lengths for
// each speed
redflowPolytropicEfficiency[i][j] = flowPolyEff[i][j] / speed[i];
redpolytropicEfficiency[i][j] = polyEff[i][j];
reducedPolytropicEfficiencyFitter.add(redflowPolytropicEfficiency[i][j],
redpolytropicEfficiency[i][j]);
}

// Fill remaining slots with default values (e.g., 0) if arrays are shorter
for (int j = flow[i].length; j < maxLength; j++) {
redflow[i][j] = 0;
for (int j = flowPolytropicEfficiency[i].length; j < maxLengthPolyEff; j++) {
redflowPolytropicEfficiency[i][j] = 0;
redpolytropicEfficiency[i][j] = 0;
redhead[i][j] = 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;
import org.apache.commons.math3.fitting.WeightedObservedPoints;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.process.equipment.stream.Stream;
Expand Down Expand Up @@ -123,7 +122,9 @@
*/

/**
* <p>CompressorChartAlternativeMapLookup class.</p>
* <p>
* CompressorChartAlternativeMapLookup class.
* </p>
*
* @author asmund
* @version $Id: $Id
Expand All @@ -148,10 +149,6 @@ public class CompressorChartAlternativeMapLookup
double refZ;
private boolean useRealKappa = false;
double[] chartConditions = null;
final WeightedObservedPoints reducedHeadFitter = new WeightedObservedPoints();
final WeightedObservedPoints reducedFlowFitter = new WeightedObservedPoints();
final WeightedObservedPoints fanLawCorrectionFitter = new WeightedObservedPoints();
final WeightedObservedPoints reducedPolytropicEfficiencyFitter = new WeightedObservedPoints();
PolynomialFunction reducedHeadFitterFunc = null;
PolynomialFunction reducedPolytropicEfficiencyFunc = null;
PolynomialFunction fanLawCorrectionFunc = null;
Expand All @@ -167,7 +164,15 @@ public CompressorChartAlternativeMapLookup() {}
/** {@inheritDoc} */
@Override
public void addCurve(double speed, double[] flow, double[] head, double[] polytropicEfficiency) {
CompressorCurve curve = new CompressorCurve(speed, flow, head, polytropicEfficiency);
addCurve(speed, flow, head, flow, polytropicEfficiency);
}

/** {@inheritDoc} */
@Override
public void addCurve(double speed, double[] flow, double[] head,
double[] flowPolytropicEfficiency, double[] polytropicEfficiency) {
CompressorCurve curve =
new CompressorCurve(speed, flow, head, flowPolytropicEfficiency, polytropicEfficiency);
chartValues.add(curve);
chartSpeeds.add(speed);
}
Expand All @@ -182,8 +187,22 @@ public void addCurve(double speed, double[] flow, double[] head, double[] polytr
@Override
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] polyEff) {
setCurves(chartConditions, speed, flow, head, flow, polyEff);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* Sets the compressor curves based on the provided chart conditions, speed, flow, head,
* flowPolytrpicEfficiency and polytropic efficiency values.
*/
@Override
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] flowPolyEff, double[][] polyEff) {
for (int i = 0; i < speed.length; i++) {
CompressorCurve curve = new CompressorCurve(speed[i], flow[i], head[i], polyEff[i]);
CompressorCurve curve =
new CompressorCurve(speed[i], flow[i], head[i], flowPolyEff[i], polyEff[i]);
chartValues.add(curve);
chartSpeeds.add(speed[i]);
}
Expand Down Expand Up @@ -291,8 +310,8 @@ public double getPolytropicEfficiency(double flow, double speed) {

for (int i = 0; i < closestRefSpeeds.size(); i++) {
s = closestRefSpeeds.get(i);
PolynomialSplineFunction psf =
asi.interpolate(getCurveAtRefSpeed(s).flow, getCurveAtRefSpeed(s).polytropicEfficiency);
PolynomialSplineFunction psf = asi.interpolate(getCurveAtRefSpeed(s).flowPolytropicEfficiency,
getCurveAtRefSpeed(s).polytropicEfficiency);
tempEffs.add(psf.value(flow));
}

Expand Down Expand Up @@ -578,7 +597,7 @@ public static void main(String[] args) {
operations.add(stream_1);
operations.add(comp1);
operations.run();
operations.displayResult();
// operations.displayResult();

System.out.println("power " + comp1.getPower());
System.out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public interface CompressorChartInterface extends Cloneable {
*/
public void addCurve(double speed, double[] flow, double[] head, double[] polytropicEfficiency);

/**
* This method is used add a curve to the CompressorChart object.
*
* @param speed a double
* @param flowHead an array of type double
* @param head an array of type double
* @param flowPolytropicEfficiency an array of type double
* @param polytropicEfficiency an array of type double
*/
public void addCurve(double speed, double[] flowHead, double[] head,
double[] flowPolytropicEfficiency, double[] polytropicEfficiency);

/**
* This method is used add a set of curves to the CompressorChart object.
*
Expand All @@ -31,6 +43,19 @@ public interface CompressorChartInterface extends Cloneable {
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] polyEff);

/**
* This method is used add a set of curves to the CompressorChart object.
*
* @param chartConditions an array of type double
* @param speed an array of type double
* @param flow an array of type double
* @param head an array of type double
* @param flowPolyEff an array of type double
* @param polyEff an array of type double
*/
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] flowPolyEff, double[][] polyEff);

/**
* Get method for polytropic head from reference curves.
*
Expand Down Expand Up @@ -117,8 +142,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
* setSurgeCurve.
* </p>
*
* @param surgeCurve a {@link neqsim.process.equipment.compressor.SurgeCurve}
* object
* @param surgeCurve a {@link neqsim.process.equipment.compressor.SurgeCurve} object
*/
public void setSurgeCurve(SurgeCurve surgeCurve);

Expand All @@ -136,8 +160,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
* setStoneWallCurve.
* </p>
*
* @param stoneWallCurve a
* {@link neqsim.process.equipment.compressor.StoneWallCurve} object
* @param stoneWallCurve a {@link neqsim.process.equipment.compressor.StoneWallCurve} object
*/
public void setStoneWallCurve(StoneWallCurve stoneWallCurve);

Expand Down Expand Up @@ -168,7 +191,9 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
public int hashCode();

/**
* <p>getFlow.</p>
* <p>
* getFlow.
* </p>
*
* @param head a double
* @param speed a double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class CompressorCurve implements java.io.Serializable {
private static final long serialVersionUID = 1000;
public double[] flow;
public double[] flowPolytropicEfficiency;
public double[] head;
public double[] polytropicEfficiency;
public double speed = 1000.0;
Expand All @@ -25,6 +26,7 @@ public class CompressorCurve implements java.io.Serializable {
*/
public CompressorCurve() {
flow = new double[] {453.2, 600.0, 750.0};
flowPolytropicEfficiency = Arrays.copyOf(flow, flow.length);
head = new double[] {1000.0, 900.0, 800.0};
polytropicEfficiency = new double[] {78.0, 79.0, 78.0};
}
Expand All @@ -43,6 +45,27 @@ public CompressorCurve(double speed, double[] flow, double[] head,
double[] polytropicEfficiency) {
this.speed = speed;
this.flow = flow;
flowPolytropicEfficiency = Arrays.copyOf(flow, flow.length);
this.head = head;
this.polytropicEfficiency = polytropicEfficiency;
}

/**
* <p>
* Constructor for CompressorCurve.
* </p>
*
* @param speed a double
* @param flow an array of type double
* @param head an array of type double
* @param flowPolytropicEfficiency an array of type double
* @param polytropicEfficiency an array of type double
*/
public CompressorCurve(double speed, double[] flow, double[] head,
double[] flowPolytropicEfficiency, double[] polytropicEfficiency) {
this.speed = speed;
this.flow = flow;
this.flowPolytropicEfficiency = flowPolytropicEfficiency;
this.head = head;
this.polytropicEfficiency = polytropicEfficiency;
}
Expand All @@ -55,6 +78,7 @@ public int hashCode() {
result = prime * result + Arrays.hashCode(flow);
result = prime * result + Arrays.hashCode(head);
result = prime * result + Arrays.hashCode(polytropicEfficiency);
result = prime * result + Arrays.hashCode(flowPolytropicEfficiency);
result = prime * result + Objects.hash(speed);
return result;
}
Expand All @@ -73,6 +97,7 @@ public boolean equals(Object obj) {
}
CompressorCurve other = (CompressorCurve) obj;
return Arrays.equals(flow, other.flow) && Arrays.equals(head, other.head)
&& Arrays.equals(flowPolytropicEfficiency, other.flowPolytropicEfficiency)
&& Arrays.equals(polytropicEfficiency, other.polytropicEfficiency)
&& Double.doubleToLongBits(speed) == Double.doubleToLongBits(other.speed);
}
Expand Down

0 comments on commit d1007e2

Please sign in to comment.