From b4367be81f1eb42c1abcb855e575d6efd4b5103f Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:01:44 +0200 Subject: [PATCH] work on standards (#805) * work on standards * add getter for number of elements * update * update * update * update --- .../processEquipment/util/PressureDrop.java | 2 + src/main/java/neqsim/standards/Standard.java | 9 ++++ .../neqsim/standards/StandardInterface.java | 2 + .../standards/gasQuality/Draft_ISO18453.java | 6 +-- .../gasQuality/GasChromotograpyhBase.java | 14 +++--- .../gasQuality/Standard_ISO6974.java | 27 ++++++++++++ .../gasQuality/SulfurSpecificationMethod.java | 17 ++++++-- .../standards/salesContract/BaseContract.java | 27 ++++++------ .../salesContract/ContractSpecification.java | 28 ++++++------ .../neqsim/thermo/atomElement/Element.java | 15 +++++++ .../commercial/GASCONTRACTSPECIFICATIONS.csv | 12 +++++- .../salesContract/BaseContractTest.java | 43 ++++++++++++++----- 12 files changed, 150 insertions(+), 52 deletions(-) create mode 100644 src/main/java/neqsim/standards/gasQuality/Standard_ISO6974.java diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/PressureDrop.java b/src/main/java/neqsim/processSimulation/processEquipment/util/PressureDrop.java index 689ce3712d..38dc472117 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/util/PressureDrop.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/PressureDrop.java @@ -29,6 +29,8 @@ public class PressureDrop extends ThrottlingValve { *

* Constructor for PressureDrop. *

+ * + * @param name the name of the pressure drop unit */ public PressureDrop(String name) { super(name); diff --git a/src/main/java/neqsim/standards/Standard.java b/src/main/java/neqsim/standards/Standard.java index fba2334260..4a27d526e0 100644 --- a/src/main/java/neqsim/standards/Standard.java +++ b/src/main/java/neqsim/standards/Standard.java @@ -36,6 +36,7 @@ public abstract class Standard extends NamedBaseClass implements StandardInterfa protected SystemInterface thermoSystem; protected ThermodynamicOperations thermoOps; private String referenceState = "real"; // "ideal"real + private double referencePressure = 70.0; /** * Constructor for Standard. @@ -197,4 +198,12 @@ public String getReferenceState() { public void setReferenceState(String referenceState) { this.referenceState = referenceState; } + + public void setReferencePressure(double referencePressure) { + this.referencePressure = referencePressure; + } + + public double getReferencePressure(){ + return referencePressure; + } } diff --git a/src/main/java/neqsim/standards/StandardInterface.java b/src/main/java/neqsim/standards/StandardInterface.java index d19c26a57e..7140224cc2 100644 --- a/src/main/java/neqsim/standards/StandardInterface.java +++ b/src/main/java/neqsim/standards/StandardInterface.java @@ -164,4 +164,6 @@ public interface StandardInterface { * @param resultTable an array of {@link java.lang.String} objects */ public void setResultTable(String[][] resultTable); + + public void setReferencePressure(double referencePressure); } diff --git a/src/main/java/neqsim/standards/gasQuality/Draft_ISO18453.java b/src/main/java/neqsim/standards/gasQuality/Draft_ISO18453.java index d0c94eecc2..7798b6aa7a 100644 --- a/src/main/java/neqsim/standards/gasQuality/Draft_ISO18453.java +++ b/src/main/java/neqsim/standards/gasQuality/Draft_ISO18453.java @@ -17,12 +17,10 @@ public class Draft_ISO18453 extends neqsim.standards.Standard { private static final long serialVersionUID = 1L; static Logger logger = LogManager.getLogger(Draft_ISO18453.class); - String dewPointTemperatureUnit = "C"; String pressureUnit = "bar"; double dewPointTemperature = 273.0; double dewPointTemperatureSpec = -12.0; - double specPressure = 70.0; double initTemperature = 273.15; SystemInterface thermoSystem; ThermodynamicOperations thermoOps; @@ -41,7 +39,7 @@ public Draft_ISO18453(SystemInterface thermoSystem) { this.thermoSystem = thermoSystem; } else { // System.out.println("setting model GERG water..."); - this.thermoSystem = new SystemGERGwaterEos(initTemperature, specPressure); + this.thermoSystem = new SystemGERGwaterEos(initTemperature, getReferencePressure()); for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { this.thermoSystem.addComponent(thermoSystem.getPhase(0).getComponent(i).getName(), thermoSystem.getPhase(0).getComponent(i).getNumberOfmoles()); @@ -61,7 +59,7 @@ public Draft_ISO18453(SystemInterface thermoSystem) { @Override public void calculate() { this.thermoSystem.setTemperature(initTemperature); - this.thermoSystem.setPressure(specPressure); + this.thermoSystem.setPressure(getReferencePressure()); try { this.thermoOps.waterDewPointTemperatureFlash(); diff --git a/src/main/java/neqsim/standards/gasQuality/GasChromotograpyhBase.java b/src/main/java/neqsim/standards/gasQuality/GasChromotograpyhBase.java index 7ec3a1624e..44fe5fc107 100644 --- a/src/main/java/neqsim/standards/gasQuality/GasChromotograpyhBase.java +++ b/src/main/java/neqsim/standards/gasQuality/GasChromotograpyhBase.java @@ -12,7 +12,7 @@ */ public class GasChromotograpyhBase extends neqsim.standards.Standard { private static final long serialVersionUID = 1L; - String componentName = "", unit = "mol%"; + String unit = "mol%"; /** *

@@ -20,13 +20,13 @@ public class GasChromotograpyhBase extends neqsim.standards.Standard { *

* * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object - * @param component a {@link java.lang.String} object + * */ - public GasChromotograpyhBase(SystemInterface thermoSystem, String component) { - super("gas cromotography", "Gas composition", thermoSystem); - this.componentName = component; + public GasChromotograpyhBase(SystemInterface thermoSystem) { + super("gas chromotography", "Gas composition", thermoSystem); } + /** {@inheritDoc} */ @Override public void calculate() { @@ -36,7 +36,7 @@ public void calculate() { /** {@inheritDoc} */ @Override - public double getValue(String returnParameter, java.lang.String returnUnit) { + public double getValue(String componentName, java.lang.String returnUnit) { unit = returnUnit; if (returnUnit.equals("mol%")) { return 100 * thermoSystem.getPhase(0).getComponent(componentName).getz(); @@ -50,7 +50,7 @@ public double getValue(String returnParameter, java.lang.String returnUnit) { /** {@inheritDoc} */ @Override - public double getValue(String returnParameter) { + public double getValue(String componentName) { return thermoSystem.getPhase(0).getComponent(componentName).getz(); } diff --git a/src/main/java/neqsim/standards/gasQuality/Standard_ISO6974.java b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6974.java new file mode 100644 index 0000000000..e21273f52d --- /dev/null +++ b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6974.java @@ -0,0 +1,27 @@ +package neqsim.standards.gasQuality; + +import neqsim.thermo.system.SystemInterface; + +/** + *

+ * Standard_ISO6974 class. + *

+ * + * @author ESOL + * @version $Id: $Id + */ +public class Standard_ISO6974 extends GasChromotograpyhBase { + private static final long serialVersionUID = 1L; + + /** + *

+ * Constructor for Standard_ISO6974. + *

+ * + * @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object + */ + public Standard_ISO6974(SystemInterface thermoSystem) { + super(thermoSystem); + setName("ISO6974"); + } +} diff --git a/src/main/java/neqsim/standards/gasQuality/SulfurSpecificationMethod.java b/src/main/java/neqsim/standards/gasQuality/SulfurSpecificationMethod.java index a448274f74..868ffe1b09 100644 --- a/src/main/java/neqsim/standards/gasQuality/SulfurSpecificationMethod.java +++ b/src/main/java/neqsim/standards/gasQuality/SulfurSpecificationMethod.java @@ -12,7 +12,6 @@ */ public class SulfurSpecificationMethod extends neqsim.standards.Standard { private static final long serialVersionUID = 1L; - SystemInterface thermoSystem; String unit = "ppm"; double H2Scontent = 0.0; @@ -37,12 +36,24 @@ public void calculate() { @Override public double getValue(String returnParameter, java.lang.String returnUnit) { thermoSystem.init(0); - if (thermoSystem.getPhase(0).hasComponent("H2S")) { - if (returnParameter.equals("H2S content")) { + if (returnParameter.equals("H2S")) { + if (thermoSystem.getPhase(0).hasComponent("H2S")) { H2Scontent = thermoSystem.getPhase(0).getComponent("H2S").getx() * 1e6; return H2Scontent; + } else { + return 0.0; } } + if (returnParameter.equals("Total sulfur")) { + double sulfurcontent = 0.0; + if (thermoSystem.getPhase(0).hasComponent("H2S")) { + sulfurcontent += thermoSystem.getPhase(0).getComponent("H2S").getx() * 1e6; + } + if (thermoSystem.getPhase(0).hasComponent("SO2")) { + sulfurcontent += thermoSystem.getPhase(0).getComponent("So2").getx() * 1e6; + } + return sulfurcontent; + } return 0.0; } diff --git a/src/main/java/neqsim/standards/salesContract/BaseContract.java b/src/main/java/neqsim/standards/salesContract/BaseContract.java index e8cee10156..70f73082d9 100644 --- a/src/main/java/neqsim/standards/salesContract/BaseContract.java +++ b/src/main/java/neqsim/standards/salesContract/BaseContract.java @@ -18,6 +18,7 @@ import neqsim.standards.gasQuality.BestPracticeHydrocarbonDewPoint; import neqsim.standards.gasQuality.Draft_ISO18453; import neqsim.standards.gasQuality.GasChromotograpyhBase; +import neqsim.standards.gasQuality.Standard_ISO6974; import neqsim.standards.gasQuality.Standard_ISO6976; import neqsim.standards.gasQuality.SulfurSpecificationMethod; import neqsim.standards.gasQuality.UKspecifications_ICF_SI; @@ -82,13 +83,14 @@ public BaseContract(SystemInterface system, String terminal, String country) { while (dataSet.next()) { numb++; StandardInterface method = getMethod(system, dataSet.getString("METHOD")); + double referencePressure = Double.parseDouble(dataSet.getString("ReferencePbar")); + method.setReferencePressure(referencePressure); spesifications.add(getSpecification(method, dataSet.getString("NAME"), dataSet.getString("SPECIFICATION"), dataSet.getString("COUNTRY"), dataSet.getString("TERMINAL"), Double.parseDouble(dataSet.getString("MINVALUE")), Double.parseDouble(dataSet.getString("MAXVALUE")), dataSet.getString("UNIT"), Double.parseDouble(dataSet.getString("ReferenceTdegC")), - Double.parseDouble(dataSet.getString("ReferenceTdegC")), - Double.parseDouble(dataSet.getString("ReferencePbar")), ""));// dataSet.getString("Comments")); + Double.parseDouble(dataSet.getString("ReferenceTdegC")), referencePressure, ""));// dataSet.getString("Comments")); System.out.println(dataSet.getString("Comments")); System.out.println("specification added..." + numb); } @@ -110,19 +112,18 @@ public BaseContract(SystemInterface system, String terminal, String country) { */ public StandardInterface getMethod(SystemInterface system, String methodName) { if (methodName.equals("ISO18453")) { + Draft_ISO18453 standard = new Draft_ISO18453(system); + standard.setReferencePressure(specificationsNumber); return new Draft_ISO18453(system); } - if (methodName.equals("CO2")) { - return new GasChromotograpyhBase(system, "CO2"); - } - if (methodName.equals("H2S")) { - return new GasChromotograpyhBase(system, "H2S"); + if (methodName.equals("ISO6974")) { + return new Standard_ISO6974(system); } if (methodName.equals("Total sulphur")) { - return new GasChromotograpyhBase(system, "H2S"); + return new GasChromotograpyhBase(system); } if (methodName.equals("oxygen")) { - return new GasChromotograpyhBase(system, "oxygen"); + return new Standard_ISO6974(system); } if (methodName.equals("ISO6976")) { return new Standard_ISO6976(system); @@ -180,12 +181,12 @@ public void runCheck() { logger.error(ex.getMessage(), ex); } spesification.getStandard().setSalesContract(this); - System.out.println("Type: " + spesification.getDescription() + " Standard " + System.out.println("Type: " + spesification.getSpecification() + " Standard " + spesification.getStandard().getName() + " : " + spesification.getStandard().isOnSpec()); - getResultTable()[j][0] = spesification.getDescription(); - getResultTable()[j][1] = Double.toString( - spesification.getStandard().getValue(spesification.getName(), spesification.getUnit())); + getResultTable()[j][0] = spesification.getSpecification(); + getResultTable()[j][1] = Double.toString(spesification.getStandard() + .getValue(spesification.getSpecification(), spesification.getUnit())); getResultTable()[j][2] = spesification.getCountry(); getResultTable()[j][3] = spesification.getTerminal(); getResultTable()[j][4] = Double.toString(spesification.getMinValue()); diff --git a/src/main/java/neqsim/standards/salesContract/ContractSpecification.java b/src/main/java/neqsim/standards/salesContract/ContractSpecification.java index ac68b9d5f0..49f9fca59f 100644 --- a/src/main/java/neqsim/standards/salesContract/ContractSpecification.java +++ b/src/main/java/neqsim/standards/salesContract/ContractSpecification.java @@ -20,7 +20,7 @@ public class ContractSpecification extends NamedBaseClass { private static final long serialVersionUID = 1L; StandardInterface standard = null; - String description = "dew point temperature specification"; + String specification = "dew point temperature specification"; private String country = ""; private String terminal = ""; private double minValue = 0; @@ -31,7 +31,9 @@ public class ContractSpecification extends NamedBaseClass { @Deprecated /** - *

Constructor for ContractSpecification.

+ *

+ * Constructor for ContractSpecification. + *

*/ public ContractSpecification() { super("ContractSpecification"); @@ -43,7 +45,7 @@ public ContractSpecification() { *

* * @param name a {@link java.lang.String} object - * @param description a {@link java.lang.String} object + * @param specification a {@link java.lang.String} object * @param country a {@link java.lang.String} object * @param terminal a {@link java.lang.String} object * @param standard a {@link neqsim.standards.StandardInterface} object @@ -55,14 +57,14 @@ public ContractSpecification() { * @param referencePressure a double * @param comments a {@link java.lang.String} object */ - public ContractSpecification(String name, String description, String country, String terminal, + public ContractSpecification(String name, String specification, String country, String terminal, StandardInterface standard, double minValue, double maxValue, String unit, double referenceTemperature, double referenceTemperatureComb, double referencePressure, String comments) { super(name); this.country = country; this.terminal = terminal; - this.description = description; + this.specification = specification; this.standard = standard; this.unit = unit; this.setReferenceTemperatureMeasurement(referenceTemperature); @@ -92,21 +94,21 @@ public void setStandard(neqsim.standards.StandardInterface standard) { } /** - * Getter for property description. + * Getter for property specification. * - * @return Value of property description. + * @return Value of property specification. */ - public java.lang.String getDescription() { - return description; + public java.lang.String getSpecification() { + return specification; } /** - * Setter for property description. + * Setter for property specification. * - * @param description New value of property description. + * @param specification New value of property description. */ - public void setDescription(java.lang.String description) { - this.description = description; + public void setSpecification(java.lang.String specification) { + this.specification = specification; } /** diff --git a/src/main/java/neqsim/thermo/atomElement/Element.java b/src/main/java/neqsim/thermo/atomElement/Element.java index 74e35031a5..3d5777bd61 100644 --- a/src/main/java/neqsim/thermo/atomElement/Element.java +++ b/src/main/java/neqsim/thermo/atomElement/Element.java @@ -82,6 +82,21 @@ public String[] getElementNames() { return nameArray; } + /** + * GetNumberOfElements. + * + * @param elementName name of element + * @return NumberOfElements of a given type. + */ + public double getNumberOfElements(String elementName) { + for (int i = 0; i < nameArray.length; i++) { + if (nameArray[i].equals(elementName)) { + return coefArray[i]; + } + } + return 0.0; + } + /** * Getter for property coefArray. * diff --git a/src/main/resources/commercial/GASCONTRACTSPECIFICATIONS.csv b/src/main/resources/commercial/GASCONTRACTSPECIFICATIONS.csv index cd24298429..11a06f9e6d 100644 --- a/src/main/resources/commercial/GASCONTRACTSPECIFICATIONS.csv +++ b/src/main/resources/commercial/GASCONTRACTSPECIFICATIONS.csv @@ -3,7 +3,15 @@ 1,"Contract1","NORWAY",,"hydrocarbondewpointTemperature",-1000.000000000,-10.000000000,"degC","StatoilBestPracticeHydrocarbonDewPoint",0.000000000,70.000000000,"", 2,"Contract1","NORWAY",,"GCV",30000.000000000,40000.000000000,"kJ/Sm^3","ISO6976",0.000000000,1.013250000,"reference temperature of compustion=0C and reference temperature volume=15C" 3,"Contract1","NORWAY",,"H2S content",0.000000000,5.000000000,"ppm","SulfurSpecificationMethod",0.000000000,1.013250000,"", -4,"Contract1","NORWAY",,"Total sulfur content",0.000000000,30.000000000,"microg/Sm3","SulfurSpecificationMethod",0.000000000,1.013250000,"", +4,"Contract1","NORWAY",,"Total sulfur",0.000000000,30.000000000,"microg/Sm3","SulfurSpecificationMethod",0.000000000,1.013250000,"", 5,"Contract1","NORWAY",,"SuperiorWobbeIndex",20000.000000000,40000.000000000,"kJ/Sm^3","ISO6976",0.000000000,1.013250000,"", 6,"Contract1","NORWAY",,"RelativeDensity",0.600000000,1.000000000,"kg/Sm^3","ISO6976",0.000000000,1.013250000,"", -7,"Contract1","UK","UK-GSMR1996","waterdewpointTemperature",-1000.000000000,-10.000000000,"degC","ISO18453",0.000000000,70.000000000,"", \ No newline at end of file +7,"Contract1","UK","UK-GSMR1996","waterdewpointTemperature",-1000.000000000,-10.000000000,"degC","ISO18453",0.000000000,70.000000000,"", +8,"ANP","Brazil","central","waterdewpointTemperature",-1000,-45.000000000,"degC","ISO18453",0.000000000,1.000000000,"ISO6327/ASTM5454", +9,"ANP","Brazil","central","CO2",0.0,3.0,"mol%","ISO6974",0.000000000,1.000000000,"ASTM1945", +10,"ANP","Brazil","central","methane",85.0,100.0,"mol%","ISO6974",0.000000000,1.000000000,"ASTM1945", +11,"ANP","Brazil","central","ethane",0.0,12.0,"mol%","ISO6974",0.000000000,1.000000000,"ASTM1945", +12,"ANP","Brazil","central","propane",0.0,5.0,"mol%","ISO6974",0.000000000,1.000000000,"ASTM1945", +13,"ANP","Brazil","central","GCV",30000.000000000,40000.000000000,"kJ/Sm^3","ISO6976",0.000000000,1.013250000,"reference temperature of compustion=0C and reference temperature volume=15C" +3,"ANP","Brazil","central","H2S",0.000000000,5.000000000,"ppm","SulfurSpecificationMethod",0.000000000,1.013250000,"", +4,"ANP","Brazil","central","Total sulfur",0.000000000,30.000000000,"microg/Sm3","SulfurSpecificationMethod",0.000000000,1.013250000,"", diff --git a/src/test/java/neqsim/standards/salesContract/BaseContractTest.java b/src/test/java/neqsim/standards/salesContract/BaseContractTest.java index 5aaf5524ac..fe21eca0e6 100644 --- a/src/test/java/neqsim/standards/salesContract/BaseContractTest.java +++ b/src/test/java/neqsim/standards/salesContract/BaseContractTest.java @@ -1,30 +1,53 @@ package neqsim.standards.salesContract; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import neqsim.thermo.system.SystemGERGwaterEos; import neqsim.thermo.system.SystemInterface; -public class BaseContractTest extends neqsim.NeqSimTest { - @Test - void testRunCheck() { - SystemInterface testSystem = new SystemGERGwaterEos(273.15 - 5.0, 20.0); +/** + * @author ESOL + * + */ +class BaseContractTest extends neqsim.NeqSimTest { + static SystemInterface testSystem = null; + static ContractInterface standard = null; + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void testRunCheck() throws Exception { + testSystem = new SystemGERGwaterEos(273.15 - 5.0, 20.0); testSystem.addComponent("methane", 0.9); testSystem.addComponent("ethane", 0.04); testSystem.addComponent("propane", 0.02); testSystem.addComponent("n-heptane", 0.00012); testSystem.addComponent("H2S", 0.000012); - testSystem.addComponent("water", 0.0000071); + testSystem.addComponent("water", 0.000071); testSystem.addComponent("oxygen", 0.0012); - testSystem.addComponent("CO2", 0.0022); + testSystem.addComponent("CO2", 0.022); testSystem.addComponent("nitrogen", 0.022); - testSystem.createDatabase(true); testSystem.setMixingRule(8); - testSystem.init(0); + standard = new BaseContract(testSystem, "UK-GSMR1996", "UK"); + } + + /** + * Test method + */ + @Test + void testUKGSMR1996() { + standard.runCheck(); + // standard.prettyPrint(); + } - ContractInterface standard = new BaseContract(testSystem, "UK-GSMR1996", "UK"); + @Test + void testUKGSMR19962() { + standard = new BaseContract(testSystem, "central", "Brazil"); standard.runCheck(); - standard.prettyPrint(); + assertEquals(2.18817727816606, Double.parseDouble(standard.getResultTable()[1][1]), 1e-6); + // standard.prettyPrint(); } }