Skip to content

Commit

Permalink
Process new tp flash problem (#852)
Browse files Browse the repository at this point in the history
* bug: TPflash problem

* fixed bug in flash

* comment out method

---------

Co-authored-by: Sviatoslav Eroshkin <[email protected]>
  • Loading branch information
EvenSol and Sviatose authored Nov 16, 2023
1 parent 315aac2 commit a133a5b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,14 @@ public void stabilityAnalysis() {
// if(minimumGibbsEnergySystem.getPhase(0).getComponent(j).isInert()) break;
int iter = 0;
double errOld = 1.0e100;
boolean useaccsubst = true;
do {
errOld = err;
iter++;
err = 0;

if (iter <= 150 || !system.isImplementedCompositionDeriativesofFugacity()) {
if (iter % 7 == 0 && iter < 150) {
if (iter % 7 == 0 && iter < 150 && useaccsubst) {
double vec1 = 0.0;

double vec2 = 0.0;
Expand All @@ -396,9 +397,6 @@ public void stabilityAnalysis() {
err += Math.abs((logWi[i] - oldlogw[i]) / oldlogw[i]);
Wi[j][i] = Math.exp(logWi[i]);
}
if (err > errOld) {
continue;
}
} else {
for (int i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) {
oldoldoldlogw[i] = oldoldlogw[i];
Expand All @@ -423,7 +421,11 @@ public void stabilityAnalysis() {
err += Math.abs(logWi[i] - oldlogw[i]);
Wi[j][i] = Math.exp(logWi[i]);
}
if (iter > 2 && err > errOld) {
useaccsubst = false;
}
}

} else {
SimpleMatrix f = new SimpleMatrix(system.getPhases()[0].getNumberOfComponents(), 1);
SimpleMatrix df = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author ESOL
*
*/
class GudrunDegasser {
class Degasser {
static neqsim.thermo.system.SystemInterface testSystem = null;
static ThermodynamicOperations testOps = null;

Expand All @@ -35,11 +35,11 @@ void setUp() throws Exception {

/**
* Test method for
* {@link neqsim.thermodynamicOperations.flashOps.PHFlash#run()}.
*/
@Test
void testRun() {
neqsim.thermo.system.SystemInterface fluid1 = new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);
neqsim.thermo.system.SystemInterface fluid1 =
new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);

fluid1.addComponent("nitrogen", 0.110282450914383);
fluid1.addComponent("CO2", 8.92014980316162);
Expand Down Expand Up @@ -121,36 +121,40 @@ void testRun() {
molarComposition.add(2.732003176453634);
molarComposition.add(27.978388438425913);

double[] molarCompositionArray = molarComposition.stream().mapToDouble(Double::doubleValue).toArray();
double[] molarCompositionArray =
molarComposition.stream().mapToDouble(Double::doubleValue).toArray();

neqsim.thermo.system.SystemInterface fluid_test_separator = fluid1.clone();
fluid_test_separator.setMolarComposition(molarCompositionArray);

neqsim.processSimulation.processEquipment.stream.Stream inlet_stream_test_sep = new neqsim.processSimulation.processEquipment.stream.Stream(
"TEST_SEPARATOR_INLET",
fluid_test_separator);
neqsim.processSimulation.processEquipment.stream.Stream inlet_stream_test_sep =
new neqsim.processSimulation.processEquipment.stream.Stream("TEST_SEPARATOR_INLET",
fluid_test_separator);
inlet_stream_test_sep.setTemperature(72.6675872802734, "C");
inlet_stream_test_sep.setPressure(10.6767892837524, "bara");
inlet_stream_test_sep.setFlowRate(721.3143271348611, "kg/hr");
inlet_stream_test_sep.run();

neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator test_separator = new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
inlet_stream_test_sep);
neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator test_separator =
new neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator(
inlet_stream_test_sep);
test_separator.setName("TEST_SEPARATOR");
test_separator.run();
test_separator.getWaterOutStream().getThermoSystem().prettyPrint();

neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream = new neqsim.processSimulation.processEquipment.heatExchanger.Heater(
"TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream());
neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream =
new neqsim.processSimulation.processEquipment.heatExchanger.Heater(
"TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream());
heater_TP_setter_test_stream.setOutPressure(5.9061164855957 - 0.01, "bara");
heater_TP_setter_test_stream.setOutTemperature(79.8487854003906, "C");
heater_TP_setter_test_stream.run();
System.out.println("Gas out from degasser " + heater_TP_setter_test_stream.getOutStream()
.getFluid().getPhase("gas").getFlowRate("kg/hr"));
heater_TP_setter_test_stream.getOutStream().getThermoSystem().prettyPrint();

neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream2 = new neqsim.processSimulation.processEquipment.heatExchanger.Heater(
"TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream());
neqsim.processSimulation.processEquipment.heatExchanger.Heater heater_TP_setter_test_stream2 =
new neqsim.processSimulation.processEquipment.heatExchanger.Heater(
"TP_SETTER_FOR_THE_DEGASSER_TEST_SEP_STREAM", test_separator.getWaterOutStream());
heater_TP_setter_test_stream2.setOutPressure(5.9061164855957, "bara");
heater_TP_setter_test_stream2.setOutTemperature(79.8487854003906, "C");
heater_TP_setter_test_stream2.run();
Expand All @@ -174,4 +178,37 @@ private int findComponentIndex(String[] componentNames, String componentName) {
return -1; // Component not found

}


/**
* Test method for
*/
void testRun2() {
/*
* XStream xstream = new XStream(); xstream.addPermission(AnyTypePermission.ANY); // Specify the
* file path to read Path filePath = Paths.get(
* "/workspaces/neqsim/src/test/java/neqsim/thermodynamicOperations/flashOps/my_process.xml");
* String xmlContents = ""; try { //xmlContents = Files.readString(filePath); } catch
* (IOException e) { e.printStackTrace(); }
*
* // Deserialize from xml neqsim.processSimulation.processSystem.ProcessSystem operationsCopy =
* (neqsim.processSimulation.processSystem.ProcessSystem) xstream.fromXML(xmlContents);
* operationsCopy.run(); neqsim.processSimulation.processEquipment.separator.Separator
* VD02Separator = (neqsim.processSimulation.processEquipment.separator.Separator)
* operationsCopy .getUnit("Separator after CFU gas");
* neqsim.processSimulation.processEquipment.separator.Separator VD01Separator =
* (neqsim.processSimulation.processEquipment.separator.Separator) operationsCopy
* .getUnit("Separator after degasser gas");
* neqsim.processSimulation.processEquipment.separator.Separator Degasser =
* (neqsim.processSimulation.processEquipment.separator.Separator) operationsCopy
* .getUnit("Degasser");
* System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " +
* Degasser.getGasOutStream().getFlowRate("kg/hr"));
* System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " +
* VD01Separator.getGasOutStream().getFlowRate("kg/hr")); VD02Separator.getGasOutStream().run();
* System.out.println("The gas flow rate should be < 200 kg/hr, the actual value is " +
* VD02Separator.getGasOutStream().getFlowRate("kg/hr"));
*/

}
}

0 comments on commit a133a5b

Please sign in to comment.