Skip to content

Commit

Permalink
update adjuster (#900)
Browse files Browse the repository at this point in the history
* update adjuster

* fix bug adjuster

* removed output added test
  • Loading branch information
EvenSol authored Jan 9, 2024
1 parent c757026 commit ae9313d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public void run(UUID id) {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getFlowRate("kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getFlowRate(adjustedVariableUnit);
} else if (adjustedVariable.equals("pressure") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).getPressure(adjustedVariableUnit);
} else if (adjustedVariable.equals("temperature") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).getTemperature(adjustedVariableUnit);
} else {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getNumberOfMoles();
}
Expand Down Expand Up @@ -193,14 +197,19 @@ public void run(UUID id) {
double deviation = targetValue - targetValueCurrent;

error = deviation;
logger.info("adjuster deviation " + deviation + " inputValue " + inputValue);
if (iterations < 2) {
if (adjustedVariable.equals("mass flow")) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
"kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(
inputValue + Math.signum(deviation) * inputValue / 100.0, adjustedVariableUnit);
} else if (adjustedVariable.equals("pressure") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).setPressure(inputValue + deviation / 10.0,
adjustedVariableUnit);
} else if (adjustedVariable.equals("temperature") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).setTemperature(inputValue + deviation / 10.0,
adjustedVariableUnit);
} else {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
"mol/sec");
Expand All @@ -210,18 +219,20 @@ public void run(UUID id) {
double newVal = error / derivate;
if (inputValue - newVal > maxAdjustedValue) {
newVal = inputValue - maxAdjustedValue;
error = 0;
}
if (inputValue - newVal < minAdjustedValue) {
newVal = inputValue - minAdjustedValue;
error = 0;
}
if (adjustedVariable.equals("mass flow")) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
"kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
adjustedVariableUnit);
} else if (adjustedVariable.equals("pressure") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).setPressure(inputValue - newVal, adjustedVariableUnit);
} else if (adjustedVariable.equals("temperature") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).setTemperature(inputValue - newVal, adjustedVariableUnit);
} else {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
"mol/sec");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package neqsim.processSimulation.processEquipment.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class AdjusterTest {
@Test
void testRun() {

double wellheadpressure = 150.0;
double bottomholepressure = 200.0;

neqsim.thermo.system.SystemInterface fluid1 = neqsim.thermo.FluidCreator.create("light oil");
fluid1.setMixingRule("classic");

neqsim.processSimulation.processEquipment.stream.Stream stream1 =
new neqsim.processSimulation.processEquipment.stream.Stream(fluid1.clone());
stream1.setFlowRate(1.5, "MSm3/day");
stream1.setPressure(bottomholepressure, "bara");
stream1.setTemperature(75.0, "C");

neqsim.processSimulation.processEquipment.pipeline.PipeBeggsAndBrills flowline1 =
new neqsim.processSimulation.processEquipment.pipeline.PipeBeggsAndBrills(stream1);
flowline1.setDiameter(0.25);
flowline1.setPipeWallRoughness(15e-6);
flowline1.setLength(1200);
flowline1.setElevation(1200.0);
flowline1.setNumberOfIncrements(20);


neqsim.processSimulation.processEquipment.util.Adjuster adjuster =
new neqsim.processSimulation.processEquipment.util.Adjuster("adjuster");
adjuster.setTargetVariable(flowline1.getOutletStream(), "pressure", wellheadpressure, "bara");
adjuster.setAdjustedVariable(stream1, "flow", "MSm3/day");
adjuster.setMaxAdjustedValue(200.0);
adjuster.setMinAdjustedValue(0.1);
adjuster.setTolerance(1e-5);

neqsim.processSimulation.processSystem.ProcessSystem process =
new neqsim.processSimulation.processSystem.ProcessSystem();
process.add(stream1);
process.add(flowline1);
process.add(adjuster);
process.run();

assertEquals(flowline1.getOutletStream().getPressure(), 150, 1e-3);
assertEquals(flowline1.getOutletStream().getFlowRate("MSm3/day"), 4.101310260394316, 1e-3);
}

@Test
void testRun2() {

double wellheadpressure = 150.0;
double bottomholepressure = 200.0;

neqsim.thermo.system.SystemInterface fluid1 = neqsim.thermo.FluidCreator.create("light oil");
fluid1.setMixingRule("classic");

neqsim.processSimulation.processEquipment.stream.Stream stream1 =
new neqsim.processSimulation.processEquipment.stream.Stream(fluid1.clone());
stream1.setFlowRate(1.5, "MSm3/day");
stream1.setPressure(bottomholepressure, "bara");
stream1.setTemperature(75.0, "C");

neqsim.processSimulation.processEquipment.pipeline.PipeBeggsAndBrills flowline1 =
new neqsim.processSimulation.processEquipment.pipeline.PipeBeggsAndBrills(stream1);
flowline1.setDiameter(0.25);
flowline1.setPipeWallRoughness(15e-6);
flowline1.setLength(1200);
flowline1.setElevation(1200.0);
flowline1.setNumberOfIncrements(20);


neqsim.processSimulation.processEquipment.util.Adjuster adjuster =
new neqsim.processSimulation.processEquipment.util.Adjuster("adjuster");
adjuster.setTargetVariable(flowline1.getOutletStream(), "pressure", wellheadpressure, "bara");
adjuster.setAdjustedVariable(stream1, "pressure", "bara");
adjuster.setMaxAdjustedValue(220.0);
adjuster.setMinAdjustedValue(50.1);
adjuster.setTolerance(1e-5);

neqsim.processSimulation.processSystem.ProcessSystem process =
new neqsim.processSimulation.processSystem.ProcessSystem();
process.add(stream1);
process.add(flowline1);
process.add(adjuster);
process.run();

assertEquals(flowline1.getOutletStream().getPressure(), 150, 1e-3);
assertEquals(flowline1.getOutletStream().getFlowRate("MSm3/day"), 1.5, 1e-3);
}
}

0 comments on commit ae9313d

Please sign in to comment.