Skip to content

Commit

Permalink
improve json properties (#990)
Browse files Browse the repository at this point in the history
* inproved properties

* further updates

* update barrels/day

* add wt fraction

* updated method
  • Loading branch information
EvenSol authored Apr 26, 2024
1 parent 1a922be commit 87f5c4a
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public SystemInterface getThermoSystem() {

/** {@inheritDoc} */
@Override
public void displayResult() {
}
public void displayResult() {}

/**
* Create deep copy.
Expand Down Expand Up @@ -89,8 +88,7 @@ public Object getProperty(String propertyName) {

/** {@inheritDoc} */
@Override
public void setRegulatorOutSignal(double signal) {
}
public void setRegulatorOutSignal(double signal) {}

/** {@inheritDoc} */
@Override
Expand All @@ -104,9 +102,8 @@ public void setController(ControllerDeviceInterface controller) {
* Setter for the field <code>flowValveController</code>.
* </p>
*
* @param controller a
* {@link neqsim.processSimulation.controllerDevice.ControllerDeviceInterface}
* object
* @param controller a {@link neqsim.processSimulation.controllerDevice.ControllerDeviceInterface}
* object
*/
public void setFlowValveController(ControllerDeviceInterface controller) {
this.flowValveController = controller;
Expand All @@ -126,8 +123,7 @@ public MechanicalDesign getMechanicalDesign() {

/** {@inheritDoc} */
@Override
public void initMechanicalDesign() {
}
public void initMechanicalDesign() {}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -158,9 +154,7 @@ public boolean solved() {
* Getter for the field <code>energyStream</code>.
* </p>
*
* @return a
* {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
* object
* @return a {@link neqsim.processSimulation.processEquipment.stream.EnergyStream} object
*/
public EnergyStream getEnergyStream() {
return energyStream;
Expand All @@ -171,9 +165,8 @@ public EnergyStream getEnergyStream() {
* Setter for the field <code>energyStream</code>.
* </p>
*
* @param energyStream a
* {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
* object
* @param energyStream a {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
* object
*/
public void setEnergyStream(EnergyStream energyStream) {
setEnergyStream(true);
Expand Down Expand Up @@ -240,8 +233,7 @@ public double getExergyChange(String unit, double surroundingTemperature) {

/** {@inheritDoc} */
@Override
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger) {
}
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger) {}

public String conditionAnalysisMessage = "";

Expand Down
152 changes: 141 additions & 11 deletions src/main/java/neqsim/processSimulation/util/monitor/StreamResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,156 @@ public class StreamResponse {
public Double massflowGas;
public Double massflowOil;
public Double massflowAqueous;
public HashMap<String, Value> data = new HashMap<String, Value>();
public HashMap<String, HashMap<String, Value>> properties =
new HashMap<String, HashMap<String, Value>>();
public HashMap<String, HashMap<String, Value>> conditions =
new HashMap<String, HashMap<String, Value>>();
public HashMap<String, HashMap<String, Value>> composition =
new HashMap<String, HashMap<String, Value>>();

/**
* <p>
* Constructor for StreamResponse.
* </p>
*
* @param inputStream a
* {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
* object
* @param inputStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
* object
*/
public StreamResponse(StreamInterface inputStream) {

name = inputStream.getName();

data.put("temperature",
new Value(Double.toString(inputStream.getTemperature(neqsim.util.unit.Units.getSymbol("temperature"))),
HashMap<String, Value> newdata = new HashMap<String, Value>();
newdata.put("temperature",
new Value(
Double.toString(
inputStream.getTemperature(neqsim.util.unit.Units.getSymbol("temperature"))),
neqsim.util.unit.Units.getSymbol("temperature")));
data.put("pressure",
new Value(Double.toString(inputStream.getPressure(neqsim.util.unit.Units.getSymbol("pressure"))),
newdata.put("pressure",
new Value(
Double.toString(inputStream.getPressure(neqsim.util.unit.Units.getSymbol("pressure"))),
neqsim.util.unit.Units.getSymbol("pressure")));
newdata.put("molar flow",
new Value(
Double
.toString(inputStream.getFlowRate(neqsim.util.unit.Units.getSymbol("molar flow"))),
neqsim.util.unit.Units.getSymbol("molar flow")));
newdata.put("mass flow",
new Value(
Double.toString(inputStream.getFlowRate(neqsim.util.unit.Units.getSymbol("mass flow"))),
neqsim.util.unit.Units.getSymbol("mass flow")));
newdata.put("fluid model", new Value(inputStream.getFluid().getModelName(), ""));
newdata.put("enthalpy",
new Value(
Double.toString(
inputStream.getFluid().getEnthalpy(neqsim.util.unit.Units.getSymbol("enthalpy"))),
neqsim.util.unit.Units.getSymbol("enthalpy")));
conditions.put(name, newdata);

for (int i = 0; i < inputStream.getFluid().getNumberOfPhases(); i++) {
String name = inputStream.getFluid().getPhase(i).getPhaseTypeName();
newdata = new HashMap<String, Value>();
newdata.put("temperature",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getTemperature(neqsim.util.unit.Units.getSymbol("temperature"))),
neqsim.util.unit.Units.getSymbol("temperature")));
newdata.put("pressure",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getPressure(neqsim.util.unit.Units.getSymbol("pressure"))),
neqsim.util.unit.Units.getSymbol("pressure")));
newdata.put("molar flow",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getFlowRate(neqsim.util.unit.Units.getSymbol("molar flow"))),
neqsim.util.unit.Units.getSymbol("molar flow")));
newdata.put("mass flow",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getFlowRate(neqsim.util.unit.Units.getSymbol("mass flow"))),
neqsim.util.unit.Units.getSymbol("mass flow")));
newdata.put("fluid model", new Value(inputStream.getFluid().getModelName(), ""));
newdata.put("enthalpy",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getEnthalpy(neqsim.util.unit.Units.getSymbol("enthalpy"))),
neqsim.util.unit.Units.getSymbol("enthalpy")));
conditions.put(name, newdata);
}


newdata = new HashMap<String, Value>();
for (int i = 0; i < inputStream.getFluid().getNumberOfComponents(); i++) {
newdata.put(inputStream.getFluid().getComponent(i).getComponentName(), new Value(
Double.toString(inputStream.getFluid().getComponent(i).getz()), "mole fraction"));
}
composition.put(name, newdata);
for (int j = 0; j < inputStream.getFluid().getNumberOfPhases(); j++) {
newdata = new HashMap<String, Value>();
for (int i = 0; i < inputStream.getFluid().getNumberOfComponents(); i++) {
newdata.put(inputStream.getFluid().getPhase(j).getComponent(i).getComponentName(),
new Value(Double.toString(inputStream.getFluid().getPhase(j).getComponent(i).getx()),
"mole fraction"));
newdata.put(inputStream.getFluid().getPhase(j).getComponent(i).getComponentName(),
new Value(Double.toString(inputStream.getFluid().getPhase(j).getWtFrac(i)),
"weight fraction"));
composition.put(inputStream.getFluid().getPhase(j).getPhaseTypeName(), newdata);

}
}



newdata = new HashMap<String, Value>();

newdata.put("density",
new Value(
Double.toString(
inputStream.getFluid().getDensity(neqsim.util.unit.Units.getSymbol("density"))),
neqsim.util.unit.Units.getSymbol("density")));

newdata.put("molar mass", new Value(
Double.toString(
inputStream.getFluid().getMolarMass(neqsim.util.unit.Units.getSymbol("Molar Mass"))),
neqsim.util.unit.Units.getSymbol("Molar Mass")));
properties.put(inputStream.getName(), newdata);

newdata.put("flow rate", new Value(
Double.toString(
inputStream.getFluid().getFlowRate(neqsim.util.unit.Units.getSymbol("volume flow"))),
neqsim.util.unit.Units.getSymbol("volume flow")));
properties.put(inputStream.getName(), newdata);


properties.put(inputStream.getName(), newdata);

newdata = new HashMap<String, Value>();
for (

int i = 0; i < inputStream.getFluid().getNumberOfPhases(); i++) {
String name = inputStream.getFluid().getPhase(i).getPhaseTypeName();
newdata.put("density",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getDensity(neqsim.util.unit.Units.getSymbol("density"))),
neqsim.util.unit.Units.getSymbol("density")));

newdata.put("molar mass",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getMolarMass(neqsim.util.unit.Units.getSymbol("Molar Mass"))),
neqsim.util.unit.Units.getSymbol("Molar Mass")));

newdata.put("flow rate",
new Value(
Double.toString(inputStream.getFluid().getPhase(name)
.getFlowRate(neqsim.util.unit.Units.getSymbol("volume flow"))),
neqsim.util.unit.Units.getSymbol("volume flow")));
properties.put(inputStream.getName(), newdata);

properties.put(name, newdata);
}

fluid = new Fluid(inputStream.getFluid());
temperature = inputStream.getTemperature("C");
Expand All @@ -53,7 +182,9 @@ public StreamResponse(StreamInterface inputStream) {
massflow = inputStream.getFluid().getFlowRate("kg/hr");
volumeFlow = inputStream.getFluid().getFlowRate("m3/hr");

if (inputStream.getFluid().hasPhaseType("gas")) {
if (inputStream.getFluid().hasPhaseType("gas"))

{
massflowGas = inputStream.getFluid().getPhase("gas").getFlowRate("kg/hr");
} else {
massflowGas = 0.0;
Expand All @@ -75,6 +206,5 @@ public StreamResponse(StreamInterface inputStream) {
* print.
* </p>
*/
public void print() {
}
public void print() {}
}
23 changes: 14 additions & 9 deletions src/main/java/neqsim/processSimulation/util/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* @version $Id: $Id
*/
public class Report {
public static HashMap<String, List<String[]>> reports = new HashMap<>();
public static HashMap<String, String> json_reports = new HashMap<>();
private HashMap<String, List<String[]>> reports = new HashMap<>();
private HashMap<String, String> json_reports = new HashMap<>();
Gson gson = new Gson();
ProcessSystem process;
ProcessEquipmentBaseClass processEquipment;
ProcessSystem process = null;
ProcessEquipmentBaseClass processEquipment = null;

public Report(ProcessSystem process) {
this.process = process;
Expand All @@ -38,12 +38,17 @@ public Report(ProcessModule processModule) {
}

public Report(ProcessModuleBaseClass processModuleBaseClass) {
//TODO Auto-generated constructor stub
}
// TODO Auto-generated constructor stub
}

public String json() {
for (ProcessEquipmentInterface unit : process.getUnitOperations()) {
json_reports.put(unit.getName(), unit.toJson());
public String json() {
if (process != null) {
for (ProcessEquipmentInterface unit : process.getUnitOperations()) {
json_reports.put(unit.getName(), unit.toJson());
}
}
if (processEquipment != null) {
json_reports.put(processEquipment.getName(), processEquipment.toJson());
}
return new GsonBuilder().setPrettyPrinting().create().toJson(json_reports);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class Phase implements PhaseInterface {
* not known to the phase.
*/
double beta = 1.0;

/**
* Number of moles in phase. <code>numberOfMolesInPhase = numberOfMolesInSystem*beta</code>. NB!
* numberOfMolesInSystem is not known to the phase.
Expand Down Expand Up @@ -2265,6 +2266,12 @@ public double getFlowRate(String flowunit) {
return numberOfMolesInPhase * 3600.0 * 24.0 * ThermodynamicConstantsInterface.R
* ThermodynamicConstantsInterface.standardStateTemperature
/ ThermodynamicConstantsInterface.atm / 1.0e6;
} else if (flowunit.equals("lbmole/hr")) {
return numberOfMolesInPhase * 3600.0 / 1000.0 * 2.205;
} else if (flowunit.equals("lb/hr")) {
return numberOfMolesInPhase * getMolarMass() * 60.0 * 2.20462262;
} else if (flowunit.equals("barrel/day")) {
return numberOfMolesInPhase * getMolarMass() * 60.0 * 2.20462262 * 0.068;
} else {
throw new RuntimeException("failed.. unit: " + flowunit + " not supported");
}
Expand Down Expand Up @@ -2304,4 +2311,10 @@ public double getIsothermalCompressibility() {
public double getIsobaricThermalExpansivity() {
return getIsothermalCompressibility() * getdPdTVn();
}

/** {@inheritDoc} */
@Override
public String getModelName() {
return thermoPropertyModelName;
}
}
Loading

0 comments on commit 87f5c4a

Please sign in to comment.