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

added units and runtime exception #814

Merged
merged 4 commits into from
Aug 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public class ValveMechanicalDesign extends MechanicalDesign {
* Constructor for ValveMechanicalDesign.
* </p>
*
* @param equipment a {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
* @param equipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface}
* object
*/
public ValveMechanicalDesign(ProcessEquipmentInterface equipment) {
super(equipment);
Expand All @@ -49,8 +50,7 @@ public void readDesignSpecifications() {
if (getDesignStandard().containsKey("valve design codes")) {
System.out.println("valve code standard: "
+ getDesignStandard().get("valve design codes").getStandardName());
valveCvMax =
((ValveDesignStandard) getDesignStandard().get("valve design codes")).getValveCvMax();
valveCvMax = ((ValveDesignStandard) getDesignStandard().get("valve design codes")).getValveCvMax();
} else {
System.out.println("no valve code standard specified......using default");
}
Expand All @@ -65,7 +65,7 @@ public void calcDesign() {
outletPressure = valve1.getOutletPressure();
dP = inletPressure - outletPressure;

valveCvMax = valve1.getThermoSystem().getVolume("m3/hr")
valveCvMax = valve1.getThermoSystem().getFlowRate("m3/hr")
* Math.sqrt(valve1.getThermoSystem().getDensity("kg/m3") / 1000.0 / dP);
valveWeight = valveCvMax * 100.0;
setWeightTotal(valveWeight);
Expand All @@ -78,7 +78,7 @@ public void displayResults() {
Container dialogContentPane = dialog.getContentPane();
dialogContentPane.setLayout(new BorderLayout());

String[] names = {"Name", "Value", "Unit"};
String[] names = { "Name", "Value", "Unit" };

String[][] table = new String[16][3]; // createTable(getProcessEquipment().getName());

Expand Down
56 changes: 30 additions & 26 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ abstract class Phase implements PhaseInterface {

/**
* Mole fraction of this phase of system.
* <code>beta = numberOfMolesInPhase/numberOfMolesInSystem</code>. NB! numberOfMolesInSystem is
* <code>beta = numberOfMolesInPhase/numberOfMolesInSystem</code>. NB!
* numberOfMolesInSystem is
* not known to the phase.
*/
double beta = 1.0;
/**
* Number of moles in phase. <code>numberOfMolesInPhase = numberOfMolesInSystem*beta</code>. NB!
* Number of moles in phase.
* <code>numberOfMolesInPhase = numberOfMolesInSystem*beta</code>. NB!
* numberOfMolesInSystem is not known to the phase.
*/
public double numberOfMolesInPhase = 0;
Expand Down Expand Up @@ -101,7 +103,7 @@ public Phase clone() {
* addcomponent. Increase number of components and add moles to phase.
* </p>
*
* @param name Name of component to add.
* @param name Name of component to add.
* @param moles Number of moles of component to add to phase.
*/
public void addComponent(String name, double moles) {
Expand All @@ -118,7 +120,8 @@ public void addComponent(String name, double moles) {
}

if (this.hasComponent(name)) {
// should use addMoles/addMolesChemreac if adding/subtracting moles for component.
// should use addMoles/addMolesChemreac if adding/subtracting moles for
// component.
throw new RuntimeException("Component already exists in phase");
}

Expand Down Expand Up @@ -176,8 +179,8 @@ public void addMoles(int component, double dn) {
public void addMolesChemReac(int component, double dn, double totdn) {
if ((numberOfMolesInPhase + dn) / numberOfMolesInPhase < -1e-10) {
String msg = "will lead to negative number of moles in phase." + (numberOfMolesInPhase + dn);
neqsim.util.exception.InvalidInputException ex =
new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", "dn", msg);
neqsim.util.exception.InvalidInputException ex = new neqsim.util.exception.InvalidInputException(this,
"addMolesChemReac", "dn", msg);
throw new RuntimeException(ex);
}
numberOfMolesInPhase += dn;
Expand Down Expand Up @@ -284,8 +287,7 @@ public double getPressure() {
/** {@inheritDoc} */
@Override
public final double getPressure(String unit) {
neqsim.util.unit.PressureUnit presConversion =
new neqsim.util.unit.PressureUnit(getPressure(), "bara");
neqsim.util.unit.PressureUnit presConversion = new neqsim.util.unit.PressureUnit(getPressure(), "bara");
return presConversion.getValue(unit);
}

Expand Down Expand Up @@ -494,11 +496,11 @@ public double calcA(PhaseInterface phase, double temperature, double pressure, i
* calcA.
* </p>
*
* @param comp a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param comp a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param temperature a double
* @param pressure a double
* @param numbcomp a int
* @param pressure a double
* @param numbcomp a int
* @return a double
*/
public double calcA(int comp, PhaseInterface phase, double temperature, double pressure,
Expand Down Expand Up @@ -1025,6 +1027,7 @@ public double getEnthalpy(String unit) {
case "J":
conversionFactor = 1.0;
break;
case "kJ/kmol":
case "J/mol":
conversionFactor = 1.0 / getNumberOfMolesInPhase();
break;
Expand All @@ -1035,7 +1038,7 @@ public double getEnthalpy(String unit) {
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0;
break;
default:
break;
throw new RuntimeException("unit not supported " + unit);
}
return refEnthalpy * conversionFactor;
}
Expand Down Expand Up @@ -1121,7 +1124,7 @@ public double getEntropy(String unit) {
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0;
break;
default:
break;
throw new RuntimeException("unit not supported " + unit);
}
return refEntropy * conversionFactor;
}
Expand Down Expand Up @@ -1150,14 +1153,15 @@ public double getViscosity(String unit) {
double refViscosity = getViscosity(); // viscosity in kg/msec
double conversionFactor = 1.0;
switch (unit) {
case "Pas":
case "kg/msec":
conversionFactor = 1.0;
break;
case "cP":
conversionFactor = 1.0e3;
break;
default:
throw new RuntimeException();
throw new RuntimeException("unit not supported " + unit);
}
return refViscosity * conversionFactor;
}
Expand All @@ -1181,7 +1185,7 @@ public double getThermalConductivity(String unit) {
conversionFactor = 0.01;
break;
default:
throw new RuntimeException();
throw new RuntimeException("unit not supported " + unit);
}
return refConductivity * conversionFactor;
}
Expand All @@ -1207,7 +1211,7 @@ public double getConductivity(String unit) {
conversionFactor = 0.01;
break;
default:
throw new RuntimeException();
throw new RuntimeException("unit not supported " + unit);
}
return refConductivity * conversionFactor;
}
Expand All @@ -1226,7 +1230,7 @@ public void initRefPhases(boolean onlyPure) {
* </p>
*
* @param onlyPure a boolean
* @param name a {@link String} object
* @param name a {@link String} object
*/
public void initRefPhases(boolean onlyPure, String name) {
refPhase = new PhaseInterface[numberOfComponents];
Expand Down Expand Up @@ -1280,7 +1284,7 @@ public void initRefPhases(boolean onlyPure, String name) {
* getLogPureComponentFugacity.
* </p>
*
* @param k a int
* @param k a int
* @param pure a boolean
* @return a double
*/
Expand Down Expand Up @@ -1552,7 +1556,7 @@ public double getJouleThomsonCoefficient(String unit) {
conversionFactor = 1.0;
break;
default:
break;
throw new RuntimeException("unit not supported " + unit);
}
return JTcoef * conversionFactor;
}
Expand Down Expand Up @@ -1585,8 +1589,7 @@ public double getDensity(String unit) {
conversionFactor = 0.0624279606;
break;
default:
throw new RuntimeException(
"Could not create conversion factor because molar mass is NULL or 0");
throw new RuntimeException("unit not supported " + unit);
}
return refDensity * conversionFactor;
}
Expand Down Expand Up @@ -1823,7 +1826,8 @@ public void setPhysicalPropertyType(int physicalPropertyType) {
/** {@inheritDoc} */
@Override
public void setParams(PhaseInterface phase, double[][] alpha, double[][] Dij, double[][] DijT,
String[][] mixRule, double[][] intparam) {}
String[][] mixRule, double[][] intparam) {
}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -1919,7 +1923,8 @@ public final void setBeta(double b) {

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

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -2106,8 +2111,7 @@ public double[] getProperties_GERG2008() {
/** {@inheritDoc} */
@Override
public double getDensity_AGA8() {
neqsim.thermo.util.GERG.NeqSimAGA8Detail test =
new neqsim.thermo.util.GERG.NeqSimAGA8Detail(this);
neqsim.thermo.util.GERG.NeqSimAGA8Detail test = new neqsim.thermo.util.GERG.NeqSimAGA8Detail(this);
return test.getDensity();
}

Expand Down
Loading