diff --git a/src/main/java/neqsim/process/equipment/compressor/CompressorChart.java b/src/main/java/neqsim/process/equipment/compressor/CompressorChart.java index b1e859a7e..5c29db3cf 100644 --- a/src/main/java/neqsim/process/equipment/compressor/CompressorChart.java +++ b/src/main/java/neqsim/process/equipment/compressor/CompressorChart.java @@ -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; @@ -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); } @@ -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. + * + *
+ * 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) { @@ -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; } } diff --git a/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookup.java b/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookup.java index b188b364d..d35125098 100644 --- a/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookup.java +++ b/src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookup.java @@ -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; @@ -123,7 +122,9 @@ */ /** - *
CompressorChartAlternativeMapLookup class.
+ *+ * CompressorChartAlternativeMapLookup class. + *
* * @author asmund * @version $Id: $Id @@ -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; @@ -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); } @@ -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]); } @@ -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)); } @@ -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 diff --git a/src/main/java/neqsim/process/equipment/compressor/CompressorChartInterface.java b/src/main/java/neqsim/process/equipment/compressor/CompressorChartInterface.java index 078ec1800..8e07bb65f 100644 --- a/src/main/java/neqsim/process/equipment/compressor/CompressorChartInterface.java +++ b/src/main/java/neqsim/process/equipment/compressor/CompressorChartInterface.java @@ -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. * @@ -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. * @@ -117,8 +142,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r * setSurgeCurve. * * - * @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); @@ -136,8 +160,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r * setStoneWallCurve. * * - * @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); @@ -168,7 +191,9 @@ public void setReferenceConditions(double refMW, double refTemperature, double r public int hashCode(); /** - *getFlow.
+ *+ * getFlow. + *
* * @param head a double * @param speed a double diff --git a/src/main/java/neqsim/process/equipment/compressor/CompressorCurve.java b/src/main/java/neqsim/process/equipment/compressor/CompressorCurve.java index 917768953..9afba438c 100644 --- a/src/main/java/neqsim/process/equipment/compressor/CompressorCurve.java +++ b/src/main/java/neqsim/process/equipment/compressor/CompressorCurve.java @@ -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; @@ -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}; } @@ -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; + } + + /** + *+ * Constructor for CompressorCurve. + *
+ * + * @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; } @@ -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; } @@ -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); }