diff --git a/src/main/java/neqsim/processSimulation/SimulationBaseClass.java b/src/main/java/neqsim/processSimulation/SimulationBaseClass.java index 307646b6bb..30b7949a38 100644 --- a/src/main/java/neqsim/processSimulation/SimulationBaseClass.java +++ b/src/main/java/neqsim/processSimulation/SimulationBaseClass.java @@ -19,6 +19,7 @@ public abstract class SimulationBaseClass extends NamedBaseClass implements Simu protected UUID calcIdentifier; protected boolean calculateSteadyState = true; protected double time = 0; + private boolean runInSteps = false; /** *

@@ -80,4 +81,31 @@ public void increaseTime(double dt) { } this.time = this.time + dt; } + + /** + *

+ * setRunInSteps + *

+ * + * @param setRunSteps boolean set if run in steps + */ + @Override + public void setRunInSteps(boolean setRunSteps) { + runInSteps = setRunSteps; + } + + /** + *

+ * isRunInSteps. + *

+ * + * @return boolean + */ + @Override + public boolean isRunInSteps() { + return runInSteps; + } + + + } diff --git a/src/main/java/neqsim/processSimulation/SimulationInterface.java b/src/main/java/neqsim/processSimulation/SimulationInterface.java index 14f971d0bd..319426689d 100644 --- a/src/main/java/neqsim/processSimulation/SimulationInterface.java +++ b/src/main/java/neqsim/processSimulation/SimulationInterface.java @@ -61,28 +61,45 @@ public interface SimulationInterface extends NamedInterface, Runnable, Serializa public void increaseTime(double dt); /** - * {@inheritDoc} - * *

- * In this method all thermodynamic and unit operations will be calculated in a steady state - * calculation. Sets calc identifier UUID. + * setRunInSteps *

+ * + * @param setRunSteps boolean set if run in steps */ - @Override - public default void run() { - run(UUID.randomUUID()); - } + public void setRunInSteps(boolean setRunSteps); + + /** + *

+ * isRunInSteps. + *

+ * + * @return boolean + */ + public boolean isRunInSteps(); + + /** + *

+ * run + *

+ * + * @param id UUID + */ + public void run(UUID id); /** *

* run *

- * In this method all thermodynamic and unit operations will be calculated in a steady state - * calculation. Sets calc identifier UUID. * - * @param value Calc identifier UUID to set. */ - public void run(UUID value); + public default void run() { + if (isRunInSteps()) { + run_step(UUID.randomUUID()); + } else { + run(UUID.randomUUID()); + } + } /** * {@inheritDoc} diff --git a/src/main/java/neqsim/processSimulation/processSystem/ProcessModule.java b/src/main/java/neqsim/processSimulation/processSystem/ProcessModule.java index f6b5230c32..b09af67442 100644 --- a/src/main/java/neqsim/processSimulation/processSystem/ProcessModule.java +++ b/src/main/java/neqsim/processSimulation/processSystem/ProcessModule.java @@ -12,10 +12,8 @@ import neqsim.processSimulation.util.report.Report; /** - * A class representing a process module class that can contain unit operations - * and other modules. - * Module will be runnning until all recycles in this module are solved. If no - * recycle in the module + * A class representing a process module class that can contain unit operations and other modules. + * Module will be runnning until all recycles in this module are solved. If no recycle in the module * then run only once. * * @author [seros] @@ -56,8 +54,7 @@ public ProcessModule(String name) { /** * Add an unit operation to the process module. * - * @param processSystem the process system that contains the unit operations to - * be added. + * @param processSystem the process system that contains the unit operations to be added. */ public void add(ProcessSystem processSystem) { @@ -86,8 +83,7 @@ public List getAddedUnitOperations() { } /** - * Get the list of operations index. The operations index is used to follow the - * correct order of + * Get the list of operations index. The operations index is used to follow the correct order of * calculations. * * @return the list of operations index @@ -108,8 +104,7 @@ public List getAddedModules() { } /** - * Get the list of module index. The module index is used to follow the correct - * order of + * Get the list of module index. The module index is used to follow the correct order of * calculations. * * @return the list of module index @@ -203,13 +198,11 @@ public Thread runAsThread() { } /** - * Returns the unit with the given name from the list of added unit operations - * and list of added + * Returns the unit with the given name from the list of added unit operations and list of added * modules. * * @param name the name of the unit to retrieve - * @return the unit with the given name, or {@code null} if no such unit is - * found + * @return the unit with the given name, or {@code null} if no such unit is found */ public Object getUnit(String name) { for (ProcessSystem processSystem : addedUnitOperations) { @@ -229,13 +222,11 @@ public Object getUnit(String name) { } /** - * Returns the unit with the given name from the list of added unit operations - * and list of added + * Returns the unit with the given name from the list of added unit operations and list of added * modules. * * @param name the name of the unit to retrieve - * @return the unit with the given name, or {@code null} if no such unit is - * found + * @return the unit with the given name, or {@code null} if no such unit is found */ public Object getMeasurementDevice(String name) { for (ProcessSystem processSystem : addedUnitOperations) { @@ -283,6 +274,6 @@ public String getReport_json() { /** {@inheritDoc} */ @Override public void run_step(UUID id) { - + run(id); } } diff --git a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java index 0cb29c2f9f..be1dad64df 100644 --- a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java +++ b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java @@ -987,6 +987,8 @@ public String getReport_json() { return new Report(this).json(); } + + /* * @XmlRootElement private class Report extends Object{ public Double name; public * ArrayList unitOperationsReports = new ArrayList(); diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java index ee17daeede..9bd709878e 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemTest.java @@ -887,24 +887,53 @@ public void testRun_step() { dryFeedGasMidgard.setFlowRate(12.3, "MSm3/day"); operations.run_step(); dryFeedGasMidgard.setFlowRate(13.5, "MSm3/day"); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); + ProcessSystem ops2 = operations.copy(); + operations.setRunInSteps(true); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + ProcessSystem ops3 = operations.copy(); + operations.run(); + operations.run(); dryFeedGasMidgard.setFlowRate(10.0, "MSm3/day"); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); - operations.run_step(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + operations.run(); + assertEquals(1.5322819175995646E-5, dehydratedGas.getFluid().getComponent("water").getx(), + 1e-6); + + + operations.run(); + operations.run(); + operations.run(); + operations.run(); assertEquals(1.5322819175995646E-5, dehydratedGas.getFluid().getComponent("water").getx(), 1e-6); + + + + // run as time step as thread + Thread thread = operations.runAsThread(); + Thread thread2 = ops2.runAsThread(); + Thread thread3 = ops3.runAsThread(); + try { + thread.join(); + thread2.join(); + thread3.join(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + }