Skip to content

Commit 861a079

Browse files
authored
added Value as response (#988)
* added Value as response * added json report from process object * update * update * fix error.
1 parent c87dcf9 commit 861a079

File tree

9 files changed

+138
-31
lines changed

9 files changed

+138
-31
lines changed

src/main/java/neqsim/processSimulation/SimulationInterface.java

+10
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,14 @@ public default void runTransient(double dt, UUID id) {
151151
* @return a boolean
152152
*/
153153
public boolean solved();
154+
155+
/**
156+
* <p>
157+
* getReport_json
158+
* </p>
159+
* Return results of simulation in json format
160+
*
161+
* @return a String
162+
*/
163+
public String getReport_json();
154164
}

src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentBaseClass.java

+27-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface;
1616
import neqsim.processSimulation.mechanicalDesign.MechanicalDesign;
1717
import neqsim.processSimulation.processEquipment.stream.EnergyStream;
18+
import neqsim.processSimulation.util.report.Report;
1819
import neqsim.thermo.system.SystemInterface;
1920

2021
/**
@@ -58,7 +59,8 @@ public SystemInterface getThermoSystem() {
5859

5960
/** {@inheritDoc} */
6061
@Override
61-
public void displayResult() {}
62+
public void displayResult() {
63+
}
6264

6365
/**
6466
* Create deep copy.
@@ -87,7 +89,8 @@ public Object getProperty(String propertyName) {
8789

8890
/** {@inheritDoc} */
8991
@Override
90-
public void setRegulatorOutSignal(double signal) {}
92+
public void setRegulatorOutSignal(double signal) {
93+
}
9194

9295
/** {@inheritDoc} */
9396
@Override
@@ -101,8 +104,9 @@ public void setController(ControllerDeviceInterface controller) {
101104
* Setter for the field <code>flowValveController</code>.
102105
* </p>
103106
*
104-
* @param controller a {@link neqsim.processSimulation.controllerDevice.ControllerDeviceInterface}
105-
* object
107+
* @param controller a
108+
* {@link neqsim.processSimulation.controllerDevice.ControllerDeviceInterface}
109+
* object
106110
*/
107111
public void setFlowValveController(ControllerDeviceInterface controller) {
108112
this.flowValveController = controller;
@@ -122,7 +126,8 @@ public MechanicalDesign getMechanicalDesign() {
122126

123127
/** {@inheritDoc} */
124128
@Override
125-
public void initMechanicalDesign() {}
129+
public void initMechanicalDesign() {
130+
}
126131

127132
/** {@inheritDoc} */
128133
@Override
@@ -153,7 +158,9 @@ public boolean solved() {
153158
* Getter for the field <code>energyStream</code>.
154159
* </p>
155160
*
156-
* @return a {@link neqsim.processSimulation.processEquipment.stream.EnergyStream} object
161+
* @return a
162+
* {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
163+
* object
157164
*/
158165
public EnergyStream getEnergyStream() {
159166
return energyStream;
@@ -164,8 +171,9 @@ public EnergyStream getEnergyStream() {
164171
* Setter for the field <code>energyStream</code>.
165172
* </p>
166173
*
167-
* @param energyStream a {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
168-
* object
174+
* @param energyStream a
175+
* {@link neqsim.processSimulation.processEquipment.stream.EnergyStream}
176+
* object
169177
*/
170178
public void setEnergyStream(EnergyStream energyStream) {
171179
setEnergyStream(true);
@@ -232,7 +240,8 @@ public double getExergyChange(String unit, double surroundingTemperature) {
232240

233241
/** {@inheritDoc} */
234242
@Override
235-
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger) {}
243+
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger) {
244+
}
236245

237246
public String conditionAnalysisMessage = "";
238247

@@ -294,6 +303,15 @@ public String toJson() {
294303
return null;
295304
}
296305

306+
/**
307+
* {@inheritDoc}
308+
*
309+
* @return a String
310+
*/
311+
public String getReport_json() {
312+
return new Report(this).json();
313+
}
314+
297315
/** {@inheritDoc} */
298316
@Override
299317
public void run_step(UUID id) {

src/main/java/neqsim/processSimulation/processEquipment/ProcessEquipmentInterface.java

+10
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,14 @@ public default SystemInterface getFluid() {
222222
* @return a String
223223
*/
224224
public String toJson();
225+
226+
/**
227+
* <p>
228+
* getReport_json
229+
* </p>
230+
* Return results of simulation in json format
231+
*
232+
* @return a String
233+
*/
234+
public String getReport_json();
225235
}

src/main/java/neqsim/processSimulation/processSystem/ProcessModule.java

+27-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import neqsim.processSimulation.SimulationBaseClass;
1010
import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface;
1111
import neqsim.processSimulation.processEquipment.util.Recycle;
12+
import neqsim.processSimulation.util.report.Report;
1213

1314
/**
14-
* A class representing a process module class that can contain unit operations and other modules.
15-
* Module will be runnning until all recycles in this module are solved. If no recycle in the module
15+
* A class representing a process module class that can contain unit operations
16+
* and other modules.
17+
* Module will be runnning until all recycles in this module are solved. If no
18+
* recycle in the module
1619
* then run only once.
1720
*
1821
* @author [seros]
@@ -53,7 +56,8 @@ public ProcessModule(String name) {
5356
/**
5457
* Add an unit operation to the process module.
5558
*
56-
* @param processSystem the process system that contains the unit operations to be added.
59+
* @param processSystem the process system that contains the unit operations to
60+
* be added.
5761
*/
5862

5963
public void add(ProcessSystem processSystem) {
@@ -82,7 +86,8 @@ public List<ProcessSystem> getAddedUnitOperations() {
8286
}
8387

8488
/**
85-
* Get the list of operations index. The operations index is used to follow the correct order of
89+
* Get the list of operations index. The operations index is used to follow the
90+
* correct order of
8691
* calculations.
8792
*
8893
* @return the list of operations index
@@ -103,7 +108,8 @@ public List<ProcessModule> getAddedModules() {
103108
}
104109

105110
/**
106-
* Get the list of module index. The module index is used to follow the correct order of
111+
* Get the list of module index. The module index is used to follow the correct
112+
* order of
107113
* calculations.
108114
*
109115
* @return the list of module index
@@ -197,11 +203,13 @@ public Thread runAsThread() {
197203
}
198204

199205
/**
200-
* Returns the unit with the given name from the list of added unit operations and list of added
206+
* Returns the unit with the given name from the list of added unit operations
207+
* and list of added
201208
* modules.
202209
*
203210
* @param name the name of the unit to retrieve
204-
* @return the unit with the given name, or {@code null} if no such unit is found
211+
* @return the unit with the given name, or {@code null} if no such unit is
212+
* found
205213
*/
206214
public Object getUnit(String name) {
207215
for (ProcessSystem processSystem : addedUnitOperations) {
@@ -221,11 +229,13 @@ public Object getUnit(String name) {
221229
}
222230

223231
/**
224-
* Returns the unit with the given name from the list of added unit operations and list of added
232+
* Returns the unit with the given name from the list of added unit operations
233+
* and list of added
225234
* modules.
226235
*
227236
* @param name the name of the unit to retrieve
228-
* @return the unit with the given name, or {@code null} if no such unit is found
237+
* @return the unit with the given name, or {@code null} if no such unit is
238+
* found
229239
*/
230240
public Object getMeasurementDevice(String name) {
231241
for (ProcessSystem processSystem : addedUnitOperations) {
@@ -261,6 +271,14 @@ public ArrayList<String[]> getReport() {
261271
return null;
262272
}
263273

274+
/**
275+
* {@inheritDoc}
276+
*
277+
* @return a String
278+
*/
279+
public String getReport_json() {
280+
return new Report(this).json();
281+
}
264282

265283
/** {@inheritDoc} */
266284
@Override

src/main/java/neqsim/processSimulation/processSystem/ProcessModuleBaseClass.java

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import neqsim.processSimulation.controllerDevice.ControllerDeviceInterface;
1212
import neqsim.processSimulation.mechanicalDesign.MechanicalDesign;
1313
import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface;
14+
import neqsim.processSimulation.util.report.Report;
1415
import neqsim.thermo.system.SystemInterface;
1516

1617
/**
@@ -250,6 +251,14 @@ public String toJson() {
250251
return null;
251252
}
252253

254+
/**
255+
* {@inheritDoc}
256+
*
257+
* @return a String
258+
*/
259+
public String getReport_json() {
260+
return new Report(this).json();
261+
}
253262

254263
/** {@inheritDoc} */
255264
@Override

src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface;
1919
import neqsim.processSimulation.processEquipment.util.Recycle;
2020
import neqsim.processSimulation.processEquipment.util.RecycleController;
21+
import neqsim.processSimulation.util.report.Report;
2122
import neqsim.thermo.system.SystemInterface;
2223

2324
/**
@@ -977,6 +978,15 @@ public boolean equals(Object obj) {
977978
&& Objects.equals(unitOperations, other.unitOperations);
978979
}
979980

981+
/**
982+
* {@inheritDoc}
983+
*
984+
* @return a String
985+
*/
986+
public String getReport_json() {
987+
return new Report(this).json();
988+
}
989+
980990
/*
981991
* @XmlRootElement private class Report extends Object{ public Double name; public
982992
* ArrayList<ReportInterface> unitOperationsReports = new ArrayList<ReportInterface>();

src/main/java/neqsim/processSimulation/util/monitor/StreamResponse.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package neqsim.processSimulation.util.monitor;
22

3-
import java.util.ArrayList;
3+
import java.util.HashMap;
44
import neqsim.processSimulation.processEquipment.stream.StreamInterface;
55

66
/**
@@ -23,27 +23,27 @@ public class StreamResponse {
2323
public Double massflowGas;
2424
public Double massflowOil;
2525
public Double massflowAqueous;
26-
public ArrayList<String[]> data = new ArrayList<String[]>();
26+
public HashMap<String, Value> data = new HashMap<String, Value>();
2727

2828
/**
2929
* <p>
3030
* Constructor for StreamResponse.
3131
* </p>
3232
*
33-
* @param inputStream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
34-
* object
33+
* @param inputStream a
34+
* {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
35+
* object
3536
*/
3637
public StreamResponse(StreamInterface inputStream) {
3738

3839
name = inputStream.getName();
3940

40-
data.add(new String[] {"temperature",
41-
Double
42-
.toString(inputStream.getTemperature(neqsim.util.unit.Units.getSymbol("temperature"))),
43-
neqsim.util.unit.Units.getSymbol("temperature")});
44-
data.add(new String[] {"pressure",
45-
Double.toString(inputStream.getPressure(neqsim.util.unit.Units.getSymbol("pressure"))),
46-
neqsim.util.unit.Units.getSymbol("pressure")});
41+
data.put("temperature",
42+
new Value(Double.toString(inputStream.getTemperature(neqsim.util.unit.Units.getSymbol("temperature"))),
43+
neqsim.util.unit.Units.getSymbol("temperature")));
44+
data.put("pressure",
45+
new Value(Double.toString(inputStream.getPressure(neqsim.util.unit.Units.getSymbol("pressure"))),
46+
neqsim.util.unit.Units.getSymbol("pressure")));
4747

4848
fluid = new Fluid(inputStream.getFluid());
4949
temperature = inputStream.getTemperature("C");
@@ -75,5 +75,6 @@ public StreamResponse(StreamInterface inputStream) {
7575
* print.
7676
* </p>
7777
*/
78-
public void print() {}
78+
public void print() {
79+
}
7980
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package neqsim.processSimulation.util.monitor;
2+
3+
/**
4+
* Unit class nested within Units.
5+
*/
6+
public class Value {
7+
public String value;
8+
public String unit;
9+
10+
public Value(String value, String unit) {
11+
this.value = value;
12+
this.unit = unit;
13+
}
14+
15+
}

src/main/java/neqsim/processSimulation/util/report/Report.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import java.util.List;
55
import com.google.gson.Gson;
66
import com.google.gson.GsonBuilder;
7+
import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass;
78
import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface;
9+
import neqsim.processSimulation.processSystem.ProcessModule;
10+
import neqsim.processSimulation.processSystem.ProcessModuleBaseClass;
811
import neqsim.processSimulation.processSystem.ProcessSystem;
912

1013
/**
@@ -20,12 +23,25 @@ public class Report {
2023
public static HashMap<String, String> json_reports = new HashMap<>();
2124
Gson gson = new Gson();
2225
ProcessSystem process;
26+
ProcessEquipmentBaseClass processEquipment;
2327

2428
public Report(ProcessSystem process) {
2529
this.process = process;
2630
}
2731

28-
public String json() {
32+
public Report(ProcessEquipmentBaseClass processEquipmentBaseClass) {
33+
processEquipment = processEquipmentBaseClass;
34+
}
35+
36+
public Report(ProcessModule processModule) {
37+
// TODO Auto-generated constructor stub
38+
}
39+
40+
public Report(ProcessModuleBaseClass processModuleBaseClass) {
41+
//TODO Auto-generated constructor stub
42+
}
43+
44+
public String json() {
2945
for (ProcessEquipmentInterface unit : process.getUnitOperations()) {
3046
json_reports.put(unit.getName(), unit.toJson());
3147
}

0 commit comments

Comments
 (0)