diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 96f9be8dd4..db23241c53 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -2926,18 +2926,9 @@ public final void setPressure(double newPressure) { /** {@inheritDoc} */ @Override public final void setPressure(double newPressure, String unit) { - for (int i = 0; i < getMaxNumberOfPhases(); i++) { - if (unit.equals("bar") || unit.equals("bara")) { - phaseArray[i].setPressure(newPressure); - } else if (unit.equals("atm")) { - phaseArray[i].setPressure(newPressure + 0.01325); - } else if (unit.equals("barg")) { - phaseArray[i].setPressure(newPressure + 1.01325); - } else { - throw new RuntimeException( - "setting new pressure could not be done. Specified unit might not be supported"); - } - } + neqsim.util.unit.PressureUnit presConversion = + new neqsim.util.unit.PressureUnit(newPressure, unit); + setPressure(presConversion.getValue("bara")); } /** {@inheritDoc} */ diff --git a/src/test/java/neqsim/thermo/system/SystemThermoTest.java b/src/test/java/neqsim/thermo/system/SystemThermoTest.java new file mode 100644 index 0000000000..e22e64c454 --- /dev/null +++ b/src/test/java/neqsim/thermo/system/SystemThermoTest.java @@ -0,0 +1,41 @@ +package neqsim.thermo.system; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +class SystemThermoTest extends neqsim.NeqSimTest { + static neqsim.thermo.system.SystemInterface testSystem = null; + + /** + *
+ * setUp. + *
+ */ + @BeforeAll + public static void setUp() { + testSystem = new neqsim.thermo.system.SystemPrEos(298.0, 10.0); + testSystem.addComponent("nitrogen", 0.01); + testSystem.addComponent("CO2", 0.01); + testSystem.addComponent("methane", 0.68); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + } + + /** + *+ * test setPressure + *
+ */ + @Test + @DisplayName("test setPressure") + public void testTPflash2() { + assertEquals(10.0, testSystem.getPressure("bara")); + testSystem.setPressure(110000.0, "Pa"); + assertEquals(1.1, testSystem.getPressure()); + } +}