Skip to content

Commit

Permalink
chore: move main function to test
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Feb 27, 2024
1 parent ec8952b commit b05a0b0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.phase.PhaseType;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermo.system.SystemSrkCPAstatoil;
import neqsim.thermodynamicOperations.ThermodynamicOperations;

/**
Expand Down Expand Up @@ -75,22 +75,24 @@ public void run() {
system.init(1);
ops.TPflash();
double wtp = 0.0;
if (system.hasPhaseType("aqueous")) {
wtp = system.getPhase("aqueous").getComponent(inhibitor).getx()
* system.getPhase("aqueous").getComponent(inhibitor).getMolarMass()
/ (system.getPhase("aqueous").getComponent(inhibitor).getx()
* system.getPhase("aqueous").getComponent(inhibitor).getMolarMass()
+ system.getPhase("aqueous").getComponent("water").getx()
* system.getPhase("aqueous").getComponent("water").getMolarMass());
if (system.hasPhaseType(PhaseType.AQUEOUS)) {
// TODO: is this correct? seems to multplying and factoring with the same numbers twice
wtp = system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getMolarMass()
/ (system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getMolarMass()
+ system.getPhase(PhaseType.AQUEOUS).getComponent("water").getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent("water").getMolarMass());
} else {
system.addComponent(inhibitor, system.getTotalNumberOfMoles());
ops.TPflash();
wtp = system.getPhase("aqueous").getComponent(inhibitor).getx()
* system.getPhase("aqueous").getComponent(inhibitor).getMolarMass()
/ (system.getPhase("aqueous").getComponent(inhibitor).getx()
* system.getPhase("aqueous").getComponent(inhibitor).getMolarMass()
+ system.getPhase("aqueous").getComponent("water").getx()
* system.getPhase("aqueous").getComponent("water").getMolarMass());
// TODO: is this correct? seems to multplying and factoring with the same numbers twice
wtp = system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getMolarMass()
/ (system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent(inhibitor).getMolarMass()
+ system.getPhase(PhaseType.AQUEOUS).getComponent("water").getx()
* system.getPhase(PhaseType.AQUEOUS).getComponent("water").getMolarMass());
}
error = -(wtp - wtfrac);

Expand All @@ -99,51 +101,9 @@ public void run() {
logger.error(ex.getMessage(), ex);
}
} while ((Math.abs(error) > 1e-5 && iter < 100) || iter < 3);
// system.display();
}

/** {@inheritDoc} */
@Override
public void printToFile(String name) {}

/**
* <p>
* main.
* </p>
*
* @param args an array of {@link java.lang.String} objects
*/
public static void main(String[] args) {
SystemInterface testSystem = new SystemSrkCPAstatoil(273.15 + 0, 100.0);

ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem);

testSystem.addComponent("nitrogen", 79.0);
testSystem.addComponent("oxygen", 21.0);
// testSystem.addComponent("ethane", 0.10);
// testSystem.addComponent("propane", 0.050);
// testSystem.addComponent("i-butane", 0.0050);
testSystem.addComponent("MEG", 0.000001);
testSystem.addComponent("water", 0.0010);
testSystem.createDatabase(true);
testSystem.setMixingRule(10);

testSystem.init(0);
testSystem.setMultiPhaseCheck(true);
testSystem.setHydrateCheck(true);

try {
testOps.hydrateInhibitorConcentrationSet("MEG", 0.99);
double cons = 100 * testSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("MEG").getMolarMass()
/ (testSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("MEG").getMolarMass()
+ testSystem.getPhase(0).getComponent("water").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("water").getMolarMass());
logger.info("hydrate inhibitor concentration " + cons + " wt%");
} catch (Exception ex) {
ex.toString();
}
testSystem.display();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package neqsim.thermodynamicOperations.flashOps.saturationOps;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermo.system.SystemSrkCPAstatoil;
import neqsim.thermodynamicOperations.ThermodynamicOperations;

public class HydrateInhibitorwtFlashTest {
@Test
void testRun() {
SystemInterface testSystem = new SystemSrkCPAstatoil(273.15 + 0, 100.0);

ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem);

testSystem.addComponent("nitrogen", 79.0);
testSystem.addComponent("oxygen", 21.0);
// testSystem.addComponent("ethane", 0.10);
// testSystem.addComponent("propane", 0.050);
// testSystem.addComponent("i-butane", 0.0050);
testSystem.addComponent("MEG", 0.000001);
testSystem.addComponent("water", 0.0010);
testSystem.createDatabase(true);
testSystem.setMixingRule(10);

testSystem.init(0);
testSystem.setMultiPhaseCheck(true);
testSystem.setHydrateCheck(true);

try {
// creates HydrateInhibitorwtFlash object and calls run on it.
testOps.hydrateInhibitorConcentrationSet("MEG", 0.99);
double cons = 100 * testSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("MEG").getMolarMass()
/ (testSystem.getPhase(0).getComponent("MEG").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("MEG").getMolarMass()
+ testSystem.getPhase(0).getComponent("water").getNumberOfmoles()
* testSystem.getPhase(0).getComponent("water").getMolarMass());
assertEquals(98.54736778391424, cons);
} catch (Exception ex) {
ex.toString();
}
// testSystem.display();

assertEquals(0.019690143220139962,
testSystem.getPhase(0).getComponent("MEG").getNumberOfmoles());
}
}

0 comments on commit b05a0b0

Please sign in to comment.