From 4efcea62ec23c09b76d03d6cf06e3869d03e7e38 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Wed, 16 Oct 2024 04:20:35 -0300 Subject: [PATCH] set method for force single phase type (#1134) --- .../neqsim/thermo/system/SystemInterface.java | 20 +++++++++++++ .../neqsim/thermo/system/SystemThermo.java | 16 ++++++++++ .../thermo/system/SystemThermoTest.java | 29 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index 8539d9213e..00f63df4ef 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -2612,4 +2612,24 @@ public void setImplementedTemperatureDeriativesofFugacity( * @return a {@link java.lang.String} object */ public String toCompJson(); + + /** + *

+ * setForceSinglePhase - force the fluid to be single phase of type as spesified by phasetype + * input + *

+ * + * @param phasetype a {@link neqsim.thermo.phase.PhaseType} object + */ + public void setForceSinglePhase(PhaseType phasetype); + + /** + *

+ * setForceSinglePhase - force the fluid to be single phase of type as spesified by phasetype + * input. phasetypename can be GAS, OIL and AQUEOUS + *

+ * + * @param phasetypename a {@link java.lang.String} object + */ + public void setForceSinglePhase(String phasetypename); } diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 8ba0d9bbe5..608b653503 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -5071,4 +5071,20 @@ public String toCompJson() { return new GsonBuilder().create() .toJson(new neqsim.processsimulation.util.monitor.FluidComponentResponse(this)); } + + /** {@inheritDoc} */ + @Override + public void setForceSinglePhase(PhaseType phasetype) { + this.init(0); + this.setNumberOfPhases(1); + this.setMaxNumberOfPhases(1); + this.setForcePhaseTypes(true); + this.setPhaseType(0, phasetype); + } + + /** {@inheritDoc} */ + @Override + public void setForceSinglePhase(String phasetype) { + setForceSinglePhase(PhaseType.byName(phasetype)); + } } diff --git a/src/test/java/neqsim/thermo/system/SystemThermoTest.java b/src/test/java/neqsim/thermo/system/SystemThermoTest.java index bdca62a470..b70e78b437 100644 --- a/src/test/java/neqsim/thermo/system/SystemThermoTest.java +++ b/src/test/java/neqsim/thermo/system/SystemThermoTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import neqsim.thermo.ThermodynamicConstantsInterface; +import neqsim.thermo.phase.PhaseType; import neqsim.thermodynamicoperations.ThermodynamicOperations; class SystemThermoTest extends neqsim.NeqSimTest { @@ -118,4 +119,32 @@ void testDisplay() { SystemEos s = new SystemPrEos(); s.display(); } + + @Test + void TESTsetForceSinglePhase() { + 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(); + + + double density = testSystem.getDensity("kg/m3"); + + testSystem.setForceSinglePhase(PhaseType.GAS); + testSystem.initProperties(); + + assertEquals(density, testSystem.getDensity("kg/m3"), 1e-4); + + testSystem.setForceSinglePhase("GAS"); + testOps.TPflash(); + testSystem.initProperties(); + + assertEquals(density, testSystem.getDensity("kg/m3"), 1e-4); + + + } }