Skip to content

Commit

Permalink
fix bug adjuster
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Jan 9, 2024
1 parent 1ecf6b3 commit 2d1f12b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public Adjuster(String name) {
* </p>
*
* @param adjustedEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param adjstedVariable a {@link java.lang.String} object
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param adjstedVariable a {@link java.lang.String} object
*/
public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment,
String adjstedVariable, String unit) {
Expand All @@ -85,9 +84,8 @@ public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment,
* </p>
*
* @param adjustedEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param adjstedVariable a {@link java.lang.String} object
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param adjstedVariable a {@link java.lang.String} object
*/
public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment,
String adjstedVariable) {
Expand All @@ -101,11 +99,10 @@ public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment,
* </p>
*
* @param targetEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
*/
public void setTargetVariable(ProcessEquipmentInterface targetEquipment, String targetVariable,
double targetValue, String targetUnit) {
Expand All @@ -121,12 +118,11 @@ public void setTargetVariable(ProcessEquipmentInterface targetEquipment, String
* </p>
*
* @param targetEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
* @param targetPhase a {@link java.lang.String} object
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
* @param targetPhase a {@link java.lang.String} object
*/
public void setTargetVariable(ProcessEquipmentInterface targetEquipment, String targetVariable,
double targetValue, String targetUnit, String targetPhase) {
Expand All @@ -143,12 +139,11 @@ public void setTargetVariable(ProcessEquipmentInterface targetEquipment, String
* </p>
*
* @param targetEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
* @param targetPhase a {@link java.lang.String} object
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param targetVariable a {@link java.lang.String} object
* @param targetValue a double
* @param targetUnit a {@link java.lang.String} object
* @param targetPhase a {@link java.lang.String} object
* @param targetComponent a {@link java.lang.String} object
*/
public void setTargetVariable(ProcessEquipmentInterface targetEquipment, String targetVariable,
Expand Down Expand Up @@ -202,7 +197,7 @@ public void run(UUID id) {
double deviation = targetValue - targetValueCurrent;

error = deviation;
logger.info("adjuster deviation " + deviation + " inputValue " + inputValue);
System.out.println("adjuster deviation " + deviation + " inputValue " + inputValue);
if (iterations < 2) {
if (adjustedVariable.equals("mass flow")) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
Expand All @@ -211,9 +206,11 @@ public void run(UUID id) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(
inputValue + Math.signum(deviation) * inputValue / 100.0, adjustedVariableUnit);
} else if (adjustedVariable.equals("pressure") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).setPressure(inputValue + deviation / 10.0, adjustedVariableUnit);
((Stream) adjustedEquipment).setPressure(inputValue + deviation / 10.0,
adjustedVariableUnit);
} else if (adjustedVariable.equals("temperature") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).setTemperature(inputValue + deviation / 10.0, adjustedVariableUnit);
((Stream) adjustedEquipment).setTemperature(inputValue + deviation / 10.0,
adjustedVariableUnit);
} else {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
"mol/sec");
Expand All @@ -223,11 +220,9 @@ 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,
Expand Down Expand Up @@ -262,8 +257,7 @@ public boolean solved() {

/** {@inheritDoc} */
@Override
public void displayResult() {
}
public void displayResult() {}

/**
* <p>
Expand Down Expand Up @@ -318,7 +312,8 @@ public void setError(double error) {
*/
public static void main(String[] args) {
// test code for adjuster...
neqsim.thermo.system.SystemInterface testSystem = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 20.00);
neqsim.thermo.system.SystemInterface testSystem =
new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 20.00);
testSystem.addComponent("methane", 1000.00);
testSystem.createDatabase(true);
testSystem.setMixingRule(2);
Expand All @@ -328,7 +323,8 @@ public static void main(String[] args) {
adjuster1.setAdjustedVariable(stream_1, "molarFlow");
adjuster1.setTargetVariable(stream_1, "gasVolumeFlow", 10.0, "MSm3/day", "");

neqsim.processSimulation.processSystem.ProcessSystem operations = new neqsim.processSimulation.processSystem.ProcessSystem();
neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(stream_1);
operations.add(adjuster1);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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);
}
}

0 comments on commit 2d1f12b

Please sign in to comment.