Skip to content

Commit c2a56b9

Browse files
authored
update process simulation with run in step (#1011)
* update process simulation with run in step * update run step * update test for run in steps * update test for step process
1 parent d4b356c commit c2a56b9

File tree

5 files changed

+114
-47
lines changed

5 files changed

+114
-47
lines changed

src/main/java/neqsim/processSimulation/SimulationBaseClass.java

+28
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class SimulationBaseClass extends NamedBaseClass implements Simu
1919
protected UUID calcIdentifier;
2020
protected boolean calculateSteadyState = true;
2121
protected double time = 0;
22+
private boolean runInSteps = false;
2223

2324
/**
2425
* <p>
@@ -80,4 +81,31 @@ public void increaseTime(double dt) {
8081
}
8182
this.time = this.time + dt;
8283
}
84+
85+
/**
86+
* <p>
87+
* setRunInSteps
88+
* </p>
89+
*
90+
* @param setRunSteps boolean set if run in steps
91+
*/
92+
@Override
93+
public void setRunInSteps(boolean setRunSteps) {
94+
runInSteps = setRunSteps;
95+
}
96+
97+
/**
98+
* <p>
99+
* isRunInSteps.
100+
* </p>
101+
*
102+
* @return boolean
103+
*/
104+
@Override
105+
public boolean isRunInSteps() {
106+
return runInSteps;
107+
}
108+
109+
110+
83111
}

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

+29-12
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,45 @@ public interface SimulationInterface extends NamedInterface, Runnable, Serializa
6161
public void increaseTime(double dt);
6262

6363
/**
64-
* {@inheritDoc}
65-
*
6664
* <p>
67-
* In this method all thermodynamic and unit operations will be calculated in a steady state
68-
* calculation. Sets calc identifier UUID.
65+
* setRunInSteps
6966
* </p>
67+
*
68+
* @param setRunSteps boolean set if run in steps
7069
*/
71-
@Override
72-
public default void run() {
73-
run(UUID.randomUUID());
74-
}
70+
public void setRunInSteps(boolean setRunSteps);
71+
72+
/**
73+
* <p>
74+
* isRunInSteps.
75+
* </p>
76+
*
77+
* @return boolean
78+
*/
79+
public boolean isRunInSteps();
80+
81+
/**
82+
* <p>
83+
* run
84+
* </p>
85+
*
86+
* @param id UUID
87+
*/
88+
public void run(UUID id);
7589

7690
/**
7791
* <p>
7892
* run
7993
* </p>
80-
* In this method all thermodynamic and unit operations will be calculated in a steady state
81-
* calculation. Sets calc identifier UUID.
8294
*
83-
* @param value Calc identifier UUID to set.
8495
*/
85-
public void run(UUID value);
96+
public default void run() {
97+
if (isRunInSteps()) {
98+
run_step(UUID.randomUUID());
99+
} else {
100+
run(UUID.randomUUID());
101+
}
102+
}
86103

87104
/**
88105
* {@inheritDoc}

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

+10-19
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
import neqsim.processSimulation.util.report.Report;
1313

1414
/**
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
15+
* A class representing a process module class that can contain unit operations and other modules.
16+
* Module will be runnning until all recycles in this module are solved. If no recycle in the module
1917
* then run only once.
2018
*
2119
* @author [seros]
@@ -56,8 +54,7 @@ public ProcessModule(String name) {
5654
/**
5755
* Add an unit operation to the process module.
5856
*
59-
* @param processSystem the process system that contains the unit operations to
60-
* be added.
57+
* @param processSystem the process system that contains the unit operations to be added.
6158
*/
6259

6360
public void add(ProcessSystem processSystem) {
@@ -86,8 +83,7 @@ public List<ProcessSystem> getAddedUnitOperations() {
8683
}
8784

8885
/**
89-
* Get the list of operations index. The operations index is used to follow the
90-
* correct order of
86+
* Get the list of operations index. The operations index is used to follow the correct order of
9187
* calculations.
9288
*
9389
* @return the list of operations index
@@ -108,8 +104,7 @@ public List<ProcessModule> getAddedModules() {
108104
}
109105

110106
/**
111-
* Get the list of module index. The module index is used to follow the correct
112-
* order of
107+
* Get the list of module index. The module index is used to follow the correct order of
113108
* calculations.
114109
*
115110
* @return the list of module index
@@ -203,13 +198,11 @@ public Thread runAsThread() {
203198
}
204199

205200
/**
206-
* Returns the unit with the given name from the list of added unit operations
207-
* and list of added
201+
* Returns the unit with the given name from the list of added unit operations and list of added
208202
* modules.
209203
*
210204
* @param name the name of the unit to retrieve
211-
* @return the unit with the given name, or {@code null} if no such unit is
212-
* found
205+
* @return the unit with the given name, or {@code null} if no such unit is found
213206
*/
214207
public Object getUnit(String name) {
215208
for (ProcessSystem processSystem : addedUnitOperations) {
@@ -229,13 +222,11 @@ public Object getUnit(String name) {
229222
}
230223

231224
/**
232-
* Returns the unit with the given name from the list of added unit operations
233-
* and list of added
225+
* Returns the unit with the given name from the list of added unit operations and list of added
234226
* modules.
235227
*
236228
* @param name the name of the unit to retrieve
237-
* @return the unit with the given name, or {@code null} if no such unit is
238-
* found
229+
* @return the unit with the given name, or {@code null} if no such unit is found
239230
*/
240231
public Object getMeasurementDevice(String name) {
241232
for (ProcessSystem processSystem : addedUnitOperations) {
@@ -283,6 +274,6 @@ public String getReport_json() {
283274
/** {@inheritDoc} */
284275
@Override
285276
public void run_step(UUID id) {
286-
277+
run(id);
287278
}
288279
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,8 @@ public String getReport_json() {
987987
return new Report(this).json();
988988
}
989989

990+
991+
990992
/*
991993
* @XmlRootElement private class Report extends Object{ public Double name; public
992994
* ArrayList<ReportInterface> unitOperationsReports = new ArrayList<ReportInterface>();

src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java

+45-16
Original file line numberDiff line numberDiff line change
@@ -887,24 +887,53 @@ public void testRun_step() {
887887
dryFeedGasMidgard.setFlowRate(12.3, "MSm3/day");
888888
operations.run_step();
889889
dryFeedGasMidgard.setFlowRate(13.5, "MSm3/day");
890-
operations.run_step();
891-
operations.run_step();
892-
operations.run_step();
893-
operations.run_step();
894-
operations.run_step();
895-
operations.run_step();
896-
operations.run_step();
897-
operations.run_step();
890+
ProcessSystem ops2 = operations.copy();
891+
operations.setRunInSteps(true);
892+
operations.run();
893+
operations.run();
894+
operations.run();
895+
operations.run();
896+
operations.run();
897+
operations.run();
898+
ProcessSystem ops3 = operations.copy();
899+
operations.run();
900+
operations.run();
898901
dryFeedGasMidgard.setFlowRate(10.0, "MSm3/day");
899-
operations.run_step();
900-
operations.run_step();
901-
operations.run_step();
902-
operations.run_step();
903-
operations.run_step();
904-
operations.run_step();
905-
operations.run_step();
906-
operations.run_step();
902+
operations.run();
903+
operations.run();
904+
operations.run();
905+
operations.run();
906+
operations.run();
907+
operations.run();
908+
operations.run();
909+
operations.run();
910+
assertEquals(1.5322819175995646E-5, dehydratedGas.getFluid().getComponent("water").getx(),
911+
1e-6);
912+
913+
914+
operations.run();
915+
operations.run();
916+
operations.run();
917+
operations.run();
907918
assertEquals(1.5322819175995646E-5, dehydratedGas.getFluid().getComponent("water").getx(),
908919
1e-6);
920+
921+
922+
923+
// run as time step as thread
924+
Thread thread = operations.runAsThread();
925+
Thread thread2 = ops2.runAsThread();
926+
Thread thread3 = ops3.runAsThread();
927+
try {
928+
thread.join();
929+
thread2.join();
930+
thread3.join();
931+
} catch (Exception e) {
932+
e.printStackTrace();
933+
}
934+
935+
909936
}
937+
938+
910939
}

0 commit comments

Comments
 (0)