Skip to content

Commit

Permalink
added compressor test and initial code (#877)
Browse files Browse the repository at this point in the history
* added compressor test and initial code

* some more work

* some further work to get dynamic compressor to work

* strugling to find error

* improve compressor calcs

* added compressor mointor

* further work in dynamic compressors

* update

* updates

* updated

* further work

* update dynamic

* update

* update

* update

* update

* update

* update

* update

* update

* update power

* add maxminspeed setters

* check if controller is active

* removed try catch block and added check for actualFlowRateNew

* removed print to screen in test
  • Loading branch information
EvenSol authored Dec 21, 2023
1 parent 85c580e commit c09f001
Show file tree
Hide file tree
Showing 15 changed files with 869 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ControllerDeviceBaseClass extends NamedBaseClass implements Control

// Internal state of integration contribution
private double TintValue = 0.0;
boolean isActive = true;

/**
* <p>
Expand All @@ -54,6 +55,19 @@ public ControllerDeviceBaseClass() {
this("controller");
}


/** {@inheritDoc} */
@Override
public void setActive(boolean isActive) {
this.isActive = isActive;
}

/** {@inheritDoc} */
@Override
public boolean isActive() {
return isActive;
}

/**
* <p>
* Constructor for ControllerDeviceBaseClass.
Expand All @@ -80,6 +94,11 @@ public double getMeasuredValue() {
/** {@inheritDoc} */
@Override
public void runTransient(double initResponse, double dt, UUID id) {
if (!isActive) {
response = initResponse;
calcIdentifier = id;
return;
}
if (isReverseActing()) {
propConstant = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,20 @@ public default void runTransient(double initResponse, double dt) {
/** {@inheritDoc} */
@Override
public int hashCode();

/**
* <p>
* setActive
* </p>
* Set if controller is active
*/
public void setActive(boolean isActive);

/**
* <p>
* isActive
* </p>
* Specifies if controller is active
*/
public boolean isActive();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package neqsim.processSimulation.measurementDevice;

import neqsim.processSimulation.processEquipment.compressor.Compressor;

/**
* <p>
* CompressorMonitor class.
* </p>
*
* @author ESOL
* @version $Id: $Id
*/
public class CompressorMonitor extends MeasurementDeviceBaseClass {
private static final long serialVersionUID = 1000;
protected Compressor compressor = null;

/**
* <p>
* Constructor for CompressorMonitor.
* </p>
*
* @param compressor a {@link neqsim.processSimulation.processEquipment.compressor.Compressor}
* object
*/
public CompressorMonitor(Compressor compressor) {
this("Compressor Monitor", compressor);
}

/**
* <p>
* Constructor for CompressorMonitor.
* </p>
*
* @param name Name of Compressor
* @param compressor a {@link neqsim.processSimulation.processEquipment.compressor.Compressor}
*/
public CompressorMonitor(String name, Compressor compressor) {
super(name, "rpm");
this.compressor = compressor;
}

/** {@inheritDoc} */
@Override
public void displayResult() {
System.out.println("measured speed " + compressor.getSpeed());
}

/** {@inheritDoc} */
@Override
public double getMeasuredValue(String unit) {
if (unit.equals("distance to surge")) {
return compressor.getDistanceToSurge();
} else {
return compressor.getDistanceToSurge();
// return compressor.getSpeed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class Compressor extends TwoPortEquipment implements CompressorInterface
public double dH = 0.0;
public double inletEnthalpy = 0;
public double pressure = 0.0;
private int speed = 3000;
private double speed = 3000;
private double maxspeed = 30000;
private double minspeed = 0;
public double isentropicEfficiency = 1.0;
public double polytropicEfficiency = 1.0;
public boolean usePolytropicCalc = false;
Expand Down Expand Up @@ -670,6 +672,50 @@ public void run(UUID id) {
setCalculationIdentifier(id);
}

/** {@inheritDoc} */
@Override
public void runTransient(double dt, UUID id) {
if (getCalculateSteadyState()) {
run(id);
increaseTime(dt);
return;
}
runController(dt, id);

inStream.getThermoSystem().init(3);
outStream.getThermoSystem().init(3);
double head = (outStream.getThermoSystem().getEnthalpy("kJ/kg")
- inStream.getThermoSystem().getEnthalpy("kJ/kg"));
double guessFlow = inStream.getFluid().getFlowRate("m3/hr");
double actualFlowRateNew = getCompressorChart().getFlow(head, getSpeed(), guessFlow);
if (actualFlowRateNew < 0.0 || Double.isNaN(actualFlowRateNew)) {
logger.error(
"actual flow rate is negative or NaN and would lead to failure of calculation: actual flow rate "
+ actualFlowRateNew);
}
inStream.setFlowRate(actualFlowRateNew, "Am3/hr");

inStream.getThermoSystem().init(3);
inStream.getThermoSystem().initPhysicalProperties("density");
inStream.run(id);
inStream.getThermoSystem().init(3);

outStream.setFlowRate(inStream.getFlowRate("kg/hr"), "kg/hr");
outStream.run();
outStream.getThermoSystem().init(3);

inletEnthalpy = inStream.getFluid().getEnthalpy();
thermoSystem = outStream.getThermoSystem().clone();
thermoSystem.initPhysicalProperties("density");

polytropicEfficiency =
compressorChart.getPolytropicEfficiency(inStream.getFlowRate("m3/hr"), speed) / 100.0;
polytropicFluidHead = head * polytropicEfficiency;
dH = polytropicFluidHead * 1000.0 * thermoSystem.getMolarMass() / getPolytropicEfficiency()
* inStream.getThermoSystem().getTotalNumberOfMoles();
setCalculationIdentifier(id);
}

/**
* <p>
* generateCompressorCurves.
Expand Down Expand Up @@ -955,6 +1001,12 @@ public boolean isSurge(double flow, double head) {
return getAntiSurge().isSurge();
}

public double getDistanceToSurge() {
return (getInletStream().getFlowRate("m3/hr")
- getCompressorChart().getSurgeCurve().getSurgeFlow(getPolytropicFluidHead()))
/ getCompressorChart().getSurgeCurve().getSurgeFlow(getPolytropicFluidHead());
}

/**
* <p>
* isStoneWall.
Expand Down Expand Up @@ -985,9 +1037,9 @@ public void setAntiSurge(AntiSurge antiSurge) {
* Getter for the field <code>speed</code>.
* </p>
*
* @return a int
* @return a double
*/
public int getSpeed() {
public double getSpeed() {
return speed;
}

Expand All @@ -998,7 +1050,7 @@ public int getSpeed() {
*
* @param speed a int
*/
public void setSpeed(int speed) {
public void setSpeed(double speed) {
this.speed = speed;
}

Expand Down Expand Up @@ -1256,6 +1308,29 @@ public void setPropertyProfile(CompressorPropertyProfile propertyProfile) {
this.propertyProfile = propertyProfile;
}

/**
* <p>
* runController.
* </p>
*
* @param dt a double
* @param id Calculation identifier
*/
public void runController(double dt, UUID id) {
if (hasController && getController().isActive()) {
getController().runTransient(this.speed, dt, id);
this.speed = getController().getResponse();
if (this.speed > maxspeed) {
this.speed = maxspeed;
}
if (this.speed < minspeed) {
this.speed = minspeed;
}
// System.out.println("valve opening " + this.percentValveOpening + " %");
}
setCalculationIdentifier(id);
}

/** {@inheritDoc} */
@Override
public int hashCode() {
Expand Down Expand Up @@ -1310,4 +1385,20 @@ public boolean equals(Object obj) {
&& usePolytropicCalc == other.usePolytropicCalc
&& useRigorousPolytropicMethod == other.useRigorousPolytropicMethod;
}

public void setMaximumSpeed(double maxSpeed) {
this.maxspeed = maxSpeed;
}

public void setMinimumSpeed(double minspeed) {
this.minspeed = minspeed;
}

public double getMaximumSpeed() {
return maxspeed;
}

public double getMinimumSpeed() {
return minspeed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ public int getSpeed(double flow, double head) {
return (int) Math.round(newspeed);
}

/** {@inheritDoc} */
@Override
public double getFlow(double head, double speed, double guessFlow) {
int iter = 1;
double error = 1.0;
double derrordspeed = 1.0;
double newflow = guessFlow;
double newhead = 0.0;
double oldflow = newflow * 1.1;
double oldhead = getPolytropicHead(oldflow, speed);
double olderror = oldhead - head;
do {
iter++;
newhead =
getPolytropicHead(newflow, speed) / (getPolytropicEfficiency(newflow, speed) / 100.0);
error = newhead - head;
derrordspeed = (error - olderror) / (newflow - oldflow);
newflow -= error / derrordspeed;
// System.out.println("newflow " + newflow);
} while (Math.abs(error) > 1e-6 && iter < 100);

// change speed to minimize
// Math.abs(head - reducedHeadFitterFunc.value(flow / speed) * speed * speed);
return newflow;
}

/**
* <p>
* addSurgeCurve.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,10 @@ public static int bisect_left(Double[] A, double x, int lo, int hi) {
/** {@inheritDoc} */
@Override
public void plot() {}

/** {@inheritDoc} */
@Override
public double getFlow(double head, double speed, double guessFlow) {
return 0.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,41 @@ public CompressorChart generateCompressorChart(String generationOption) {
double[] chartConditions = new double[3];
chartConditions[0] = compressor.getOutletStream().getFluid().getMolarMass("kg/mol");

int refspeed = compressor.getSpeed();
double refspeed = compressor.getSpeed();
double[] speed = new double[1];
speed[0] = refspeed;
double minSpeed = refspeed / 2.0;
double maxSpeed = refspeed * 2.0;

compressor.getInletStream().getFluid().initPhysicalProperties("density");
double refflow = compressor.getInletStream().getFlowRate("m3/hr");
double[][] flow = new double[1][1];
flow[0][0] = refflow;
double[][] flow = new double[1][3];
flow[0][0] = refflow * 0.7;
flow[0][1] = refflow * 1.0;
flow[0][2] = refflow * 1.43;
double minFlow = refflow / 2.0;
double maxFlow = refflow * 2.0;

double refhead = compressor.getPolytropicHead("kJ/kg");
double[][] head = new double[1][1];
head[0][0] = refhead;

double[][] polyEff = new double[1][1];
polyEff[0][0] = compressor.getPolytropicEfficiency() * 100.0;
double refhead = compressor.getPolytropicFluidHead();
double[][] head = new double[1][3];
head[0][0] = refhead * 1.5;
head[0][1] = refhead;
head[0][2] = refhead * 0.5;

double[][] polyEff = new double[1][3];
polyEff[0][0] = compressor.getPolytropicEfficiency() * 100.0 * 0.9;
polyEff[0][1] = compressor.getPolytropicEfficiency() * 100.0;
polyEff[0][2] = compressor.getPolytropicEfficiency() * 100.0 * 0.85;
CompressorChart compChart = new CompressorChart();
compChart.setUseCompressorChart(true);
compChart.setHeadUnit("kJ/kg");
compChart.setCurves(chartConditions, speed, flow, head, polyEff);


// Generating surge curve
double minFlowSurgeFlow = 0.3 * refflow;
double refSurgeFlow = 0.5 * refflow;
double maxSurgeFlow = 0.8 * refflow;
double minFlowSurgeFlow = 0.7 * refflow;
double refSurgeFlow = 0.8 * refflow;
double maxSurgeFlow = 0.9 * refflow;
double headSurgeRef = compChart.getPolytropicHead(refSurgeFlow, refspeed);
double headSurgeMin = compChart.getPolytropicHead(minFlow, minSpeed);
double headSurgeMax = compChart.getPolytropicHead(maxSurgeFlow, maxSpeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ public void setReferenceConditions(double refMW, double refTemperature, double r
/** {@inheritDoc} */
@Override
public int hashCode();

/** {@inheritDoc} */
public double getFlow(double head, double speed, double guessFlow);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ public interface CompressorInterface extends ProcessEquipmentInterface, TwoPortI
* @return a {@link neqsim.processSimulation.processEquipment.compressor.AntiSurge} object
*/
public AntiSurge getAntiSurge();

public double getDistanceToSurge();

public void setMaximumSpeed(double maxSpeed);

public void setMinimumSpeed(double minspeed);

public double getMaximumSpeed();

public double getMinimumSpeed();
}
Loading

0 comments on commit c09f001

Please sign in to comment.