Skip to content

Commit

Permalink
Merge pull request #84 from equinor/updates_compressors
Browse files Browse the repository at this point in the history
Updates compressors
  • Loading branch information
EvenSol authored Dec 6, 2019
2 parents 87da2af + feb0931 commit f3e8c03
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.awt.*;
import java.text.*;
import javax.swing.*;

import org.apache.log4j.Logger;

import neqsim.processSimulation.mechanicalDesign.compressor.CompressorMechanicalDesign;
import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass;
import neqsim.processSimulation.processEquipment.stream.StreamInterface;
Expand All @@ -22,7 +25,7 @@
public class Compressor extends ProcessEquipmentBaseClass implements CompressorInterface {

private static final long serialVersionUID = 1000;

static Logger logger = Logger.getLogger(Compressor.class);
String name = new String();
public SystemInterface thermoSystem;
public ThermodynamicOperations thermoOps;
Expand All @@ -31,11 +34,13 @@ public class Compressor extends ProcessEquipmentBaseClass implements CompressorI
public double dH = 0.0;
public double inletEnthalpy = 0;
public double pressure = 0.0;
private int speed = 3000;
public double isentropicEfficiency = 1.0, polytropicEfficiency = 1.0;
public boolean usePolytropicCalc = false;
public boolean powerSet = false;
private CompressorChart compressorChart = new CompressorChart();
private AntiSurge antiSurge = new AntiSurge();

/**
* Creates new ThrottelValve
*/
Expand Down Expand Up @@ -66,11 +71,10 @@ public void setInletStream(StreamInterface inletStream) {
e.printStackTrace();
}
}



public void solveAntiSurge() {
if(getAntiSurge().isActive()) {
//....
if (getAntiSurge().isActive()) {
// ....
}
}

Expand Down Expand Up @@ -129,15 +133,15 @@ public double solveEfficiency(double outTemperature) {
usePolytropicCalc = useOld;
return newPoly;
}

public double findOutPressure(double hinn, double hout, double polytropicEfficiency) {
double entropy = getThermoSystem().getEntropy();
getThermoSystem().setPressure(getThermoSystem().getPressure() + 1.0);

// System.out.println("entropy inn.." + entropy);
thermoOps.PSflash(entropy);
double houtGuess = hinn + dH/polytropicEfficiency;

double houtGuess = hinn + dH / polytropicEfficiency;
thermoOps.PHflash(houtGuess, 0);
System.out.println("TEMPERATURE .." + getThermoSystem().getTemperature());
return getThermoSystem().getPressure();
Expand All @@ -153,17 +157,61 @@ public void run() {
double densInn = getThermoSystem().getDensity();
double entropy = getThermoSystem().getEntropy();
inletEnthalpy = hinn;
boolean surgeCheck = false;
double orginalMolarFLow = thermoSystem.getTotalNumberOfMoles();
double fractionAntiSurge = 0.0;
if (compressorChart.isUseCompressorChart()) {
do {
double polytropEff = getCompressorChart().getPolytropicEfficiency(thermoSystem.getFlowRate("m3/hr"),
getSpeed());
setPolytropicEfficiency(polytropEff / 100.0);
logger.info("actual inlet flow " + thermoSystem.getFlowRate("m3/hr") + " m/hr");
double head_meter = getCompressorChart().getHead(thermoSystem.getFlowRate("m3/hr"), getSpeed());
logger.info("head_meter: " + head_meter);
double temperature_inlet = thermoSystem.getTemperature();
double z_inlet = thermoSystem.getZ();
double MW = thermoSystem.getMolarMass();
double kappa = thermoSystem.getGamma();
double n = 1.0 / (1.0 - (kappa - 1.0) / kappa * 1.0 / (polytropEff / 100.0));
double head_kjkg = head_meter / 1000.0 * 9.81;
double pressureRatio = Math.pow(
(head_kjkg * 1000.0 + (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet + 273.15) / MW))
/ (n / (n - 1.0) * z_inlet * 8.314 * (temperature_inlet + 273.15) / MW),
n / (n - 1.0));
// System.out.println("pressure ratio " + pressureRatio);
logger.info("pressure ratio " + pressureRatio);
setOutletPressure(thermoSystem.getPressure() * pressureRatio);
logger.info("head " + head_meter + " m");
if (getAntiSurge().isActive()) {
logger.info("surge flow " + getCompressorChart().getSurgeCurve().getSurgeFlow(head_meter) + " m3/hr");
surgeCheck = isSurge(head_meter, thermoSystem.getFlowRate("m3/hr"));
logger.info("surge? " + surgeCheck);
}
if (getCompressorChart().getStoneWallCurve().isActive()) {
logger.info("stone wall? " + isStoneWall(head_meter, thermoSystem.getFlowRate("m3/hr")));
}
if (surgeCheck && getAntiSurge().isActive()) {
double surgeFLow = getCompressorChart().getSurgeCurve().getSurgeFlow(head_meter);
double correction = surgeFLow / thermoSystem.getFlowRate("m3/hr");
thermoSystem.setTotalNumberOfMoles(1.005 * thermoSystem.getTotalNumberOfMoles());
thermoSystem.init(3);
fractionAntiSurge = thermoSystem.getTotalNumberOfMoles() / orginalMolarFLow - 1.0;
logger.info("fractionAntiSurge: " + fractionAntiSurge);
}

powerSet = true;
dH = head_kjkg * 1000.0 * thermoSystem.getMolarMass() / getPolytropicEfficiency()*thermoSystem.getTotalNumberOfMoles();
} while (surgeCheck && getAntiSurge().isActive());
}

if (usePolytropicCalc) {

if (powerSet) {
//dH = (getPower() - hinn) / polytropicEfficiency;
double hout = hinn + dH;

findOutPressure(hinn, hout, polytropicEfficiency);
System.out.println("hout " + hout);


// dH = (getPower() - hinn) / polytropicEfficiency;
double hout = hinn * (1 - 0 + fractionAntiSurge) + dH;
thermoSystem.setPressure(pressure);
// findOutPressure(hinn, hout, polytropicEfficiency);
// System.out.println("hout " + hout);
thermoOps.PHflash(hout, 0);
} else {
int numbersteps = 40;
Expand Down Expand Up @@ -199,10 +247,9 @@ public void run() {
*/
} else {
getThermoSystem().setPressure(pressure);

// System.out.println("entropy inn.." + entropy);
thermoOps.PSflash(entropy);
double densOutIdeal = getThermoSystem().getDensity();
// double densOutIdeal = getThermoSystem().getDensity();
if (!powerSet) {
dH = (getThermoSystem().getEnthalpy() - hinn) / isentropicEfficiency;
}
Expand All @@ -212,6 +259,12 @@ public void run() {
thermoOps.PHflash(hout, 0);
}
// thermoSystem.display();

if (getCompressorChart().isUseCompressorChart() && getAntiSurge().isActive()) {
thermoSystem.setTotalNumberOfMoles(orginalMolarFLow);
thermoSystem.init(3);
}

outStream.setThermoSystem(getThermoSystem());
}

Expand Down Expand Up @@ -384,7 +437,24 @@ public AntiSurge getAntiSurge() {
return antiSurge;
}

public boolean isSurge(double flow, double head) {
return getCompressorChart().getSurgeCurve().isSurge(flow, head);
}

public boolean isStoneWall(double flow, double head) {
return getCompressorChart().getStoneWallCurve().isStoneWall(flow, head);
}

public void setAntiSurge(AntiSurge antiSurge) {
this.antiSurge = antiSurge;
}

public int getSpeed() {
return speed;
}

public void setSpeed(int speed) {
this.speed = speed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,72 @@

import java.util.*;

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.fitting.PolynomialCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoints;
import org.apache.log4j.Logger;

import neqsim.processSimulation.processEquipment.stream.Stream;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermo.system.SystemSrkEos;

public class CompressorChart {

static Logger logger = Logger.getLogger(CompressorChart.class);
ArrayList<CompressorCurve> chartValues = new ArrayList<CompressorCurve>();
SurgeCurve surgeCurve;
private SurgeCurve surgeCurve = new SurgeCurve();
private StoneWallCurve stoneWallCurve = new StoneWallCurve();
boolean isSurge = false;
boolean isStoneWall = false;
double refMW;

private boolean useCompressorChart = false;
double refTemperature;
double refPressure;
double refZ;
double[] chartConditions = null;
final WeightedObservedPoints reducedHeadFitter = new WeightedObservedPoints();
final WeightedObservedPoints reducedFlowFitter = new WeightedObservedPoints();
final WeightedObservedPoints reducedPolytropicEfficiencyFitter = new WeightedObservedPoints();
PolynomialFunction reducedHeadFitterFunc = null;
PolynomialFunction reducedPolytropicEfficiencyFunc = null;

public CompressorChart() {
}

double speed = 1000.0;
double[] flow = new double[] { 453.2, 600.0, 750.0 };
double[] head = new double[] { 1000.0, 900.0, 800.0 };
double[] polytropicEfficiency = new double[] { 78.0, 79.0, 78.0 };
public void addCurve(double speed, double[] flow, double[] head, double[] polytropicEfficiency) {
CompressorCurve curve = new CompressorCurve(speed, flow, head, polytropicEfficiency);
chartValues.add(curve);
}

double[] surgeFlow = new double[] { 453.2, 600.0, 750.0 };
double[] surgeHead = new double[] { 1000.0, 900.0, 800.0 };
surgeCurve = new SurgeCurve(surgeFlow, surgeHead);
public void setCurves(double[] chartConditions, double[] speed, double[][] flow, double[][] head,
double[][] polyEff) {
for (int i = 0; i < speed.length; i++) {
CompressorCurve curve = new CompressorCurve(speed[i], flow[i], head[i], polyEff[i]);
chartValues.add(curve);
for (int j = 0; j < flow[i].length; j++) {
reducedHeadFitter.add(flow[i][j] / speed[i], head[i][j] / speed[i] / speed[i]);
reducedPolytropicEfficiencyFitter.add(flow[i][j] / speed[i], polyEff[i][j]);
}
}
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);

reducedHeadFitterFunc = new PolynomialFunction(fitter.fit(reducedHeadFitter.toList()));
reducedPolytropicEfficiencyFunc = new PolynomialFunction(
fitter.fit(reducedPolytropicEfficiencyFitter.toList()));
setUseCompressorChart(true);
}

public void addCurve(double speed, double[] flow, double[] head, double[] polytropicEfficiency) {
CompressorCurve curve = new CompressorCurve(speed, flow, head, polytropicEfficiency);
chartValues.add(curve);
public void fitReducedCurve() {

}

public double getHead(double flow, double speed) {
return reducedHeadFitterFunc.value(flow / speed) * speed * speed;
}

public double getPolytropicEfficiency(double flow, double speed) {
return reducedPolytropicEfficiencyFunc.value(flow / speed);
}

public void addSurgeCurve(double[] flow, double[] head) {
Expand Down Expand Up @@ -71,37 +105,75 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
this.refPressure = refPressure;
this.refZ = refZ;
}

public SurgeCurve getSurgeCurve() {
return surgeCurve;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
public void setSurgeCurve(SurgeCurve surgeCurve) {
this.surgeCurve = surgeCurve;
}

public StoneWallCurve getStoneWallCurve() {
return stoneWallCurve;
}

public void setStoneWallCurve(StoneWallCurve stoneWallCurve) {
this.stoneWallCurve = stoneWallCurve;
}

public static void main(String[] args) {
SystemInterface testFluid = new SystemSrkEos(298.15, 50.0);

testFluid.addComponent("methane", 1.0);
testFluid.setMixingRule(2);
testFluid.setTotalFlowRate(1.0e6, "MSm3/day");
testFluid.setTotalFlowRate(0.635, "MSm3/day");

Stream stream_1 = new Stream("Stream1", testFluid);
Compressor comp1 = new Compressor(stream_1);
comp1.setUsePolytropicCalc(true);
comp1.setPower(1000000000000.0);
comp1.getAntiSurge().setActive(true);
// comp1.setOutletPressure(100.0);

// CompressorChart compChart = new CompressorChart();
// compChart.addCurve(1000.0, new double[] {453.2, 600.0, 750.0}, new double[]
// {1000.0, 900.0, 800.0}, new double[] {78.0, 79.0, 78.0});
// compChart.addSurgeCurve(new double[] {453.2, 600.0, 750.0}, new double[]
// {1000.0, 900.0, 800.0});
// compChart.setReferenceConditions(double refMW, double refTemperature, double refPressure, double refZ)
// comp1.setCompressorChart(compChart);

comp1.getAntiSurge().setActive(false);
comp1.setSpeed(2050);

double[] chartConditions = new double[] { 0.3, 1.0, 1.0, 1.0 };
double[] speed = new double[] { 1000.0, 2000.0, 3000.0, 4000.0 };
double[][] flow = new double[][] { { 453.2, 600.0, 750.0, 800.0 }, { 453.2, 600.0, 750.0, 800.0 },
{ 453.2, 600.0, 750.0, 800.0 }, { 453.2, 600.0, 750.0, 800.0 } };
double[][] head = new double[][] { { 10000.0, 9000.0, 8000.0, 7500.0 }, { 10000.0, 9000.0, 8000.0, 7500.0 },
{ 10000.0, 9000.0, 8000.0, 7500.0 }, { 10000.0, 9000.0, 8000.0, 7500.0 } };
double[][] polyEff = new double[][] { { 90.0, 91.0, 89.0, 88.0 }, { 90.0, 91.0, 89.0, 88.0 },
{ 90.0, 91.0, 89.0, 88.1 }, { 90.0, 91.0, 89.0, 88.1 } };
comp1.getCompressorChart().setCurves(chartConditions, speed, flow, head, polyEff);


double[] surgeflow = new double[] { 453.2, 550.0, 700.0, 800.0 };
double[] surgehead = new double[] { 6000.0, 7000.0, 8000.0, 10000.0 };
//comp1.getCompressorChart().getSurgeCurve().setCurve(chartConditions, surgeflow, surgehead);


double[] stoneWallflow = new double[] { 923.2, 950.0, 980.0, 1000.0 };
double[] stoneWallHead = new double[] { 6000.0, 7000.0, 8000.0, 10000.0 };
//comp1.getCompressorChart().getStoneWallCurve().setCurve(chartConditions, stoneWallflow, stoneWallHead);



neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(stream_1);
operations.add(comp1);
operations.run();
operations.displayResult();


System.out.println("power " + comp1.getPower());

}

boolean isUseCompressorChart() {
return useCompressorChart;
}

void setUseCompressorChart(boolean useCompressorChart) {
this.useCompressorChart = useCompressorChart;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public class CompressorCurve {

double[] flow;
double[] head;
double[] polytropicEfficiency ;
double speed = 1000.0;
public double[] flow;
public double[] head;
public double[] polytropicEfficiency ;
public double speed = 1000.0;

public CompressorCurve() {
flow = new double[] {453.2, 600.0, 750.0};
Expand Down
Loading

0 comments on commit f3e8c03

Please sign in to comment.