Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved setPressure method #619

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/neqsim/thermo/system/SystemThermoTest.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* setUp.
* </p>
*/
@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();
}

/**
* <p>
* test setPressure
* </p>
*/
@Test
@DisplayName("test setPressure")
public void testTPflash2() {
assertEquals(10.0, testSystem.getPressure("bara"));
testSystem.setPressure(110000.0, "Pa");
assertEquals(1.1, testSystem.getPressure());
}
}