Simcenter STAR-CCM+ How can I add a Java macro to my Simulation Operation pipeline?

2023-09-12T08:44:49.000-0400
Simcenter STAR-CCM+ Simcenter STAR-CCM+ Virtual Reality Teamcenter Share Simcenter STAR-CCM+ Viewer Simcenter STAR-CCM+ Application Specific Solutions

Summary

It is not currently possible to natively run Java macros from a Simulation Operations tree. It is however possible to achieve this objective by using a Java macro to control the Simulation Operations. This article provides a ready-to-use overarching macro for accomplishing this task in a straightforward way.


Details

It is not currently possible to natively run Java macros from a Simulation Operations tree. It is however possible to achieve this objective by using a Java macro to control the Simulation Operations. This article provides a ready-to-use overarching macro for accomplishing this task in a straightforward way.

Before proceeding further, please make sure you have no alternative to using Java macros. If an integrated functionality of Simcenter STAR-CCM+ exists, that would be preferable to scripting in terms of both efficiency and future maintenance.

If resorting to a macro is the only way to accomplish your task, then it is recommended to keep it “as simple as possible”. Creating simple “elementary” macros featuring the missing functionalities and using Simulation Operations for all remaining tasks is preferable to writing a long and elaborated script. You will then be able to use the overarching macro “RunSimOpsWithJava.java” attached to this article to implement an equivalent “Run Macro” operation.

To use the macro, just insert a “Set Parameter” operation in the Simulation Operation pipeline at the point at which you want your macro to be executed, and rename it as:
 
Run Macro MyMacro.java

The text and spaces must match the above string exactly, and the macro file name “MyMacro.java” must to be substituted with the name of the macro you intend to use. Define and use a dummy Parameter in this operation to have the Simulation Operations pipeline working without errors.

You can repeat the same procedure for any other macro you want to add to your pipeline. The only limitation is that you won’t be able to play a macro as the first operation as it is treated in a different way: in this case just insert another dummy operation before that.

Once you have modified your Simulation Operations pipeline according to the instructions above, set it as active and put all your macros plus “RunSimOpsWithJava.java” in the same folder. Then, instead of playing the Simulation Operation pipeline with the usual toolbar button, play the overarching macro. This will sequentially execute all your Simulation Operation pipeline blocks, and execute the associated Java macro when the keyword “Run Macro” is found.

To demonstrate the use of this tool, let’s consider the example of a pressure safety valve (PSV) in a gas pipeline. If the pressure rises above critical levels, the valve opens to relieve the pressure, causing potential safety hazard as the released fluid is generally flammable, and the gas temperature can be very high or very low. In this example a scenario where the PSV opens during an upset event, starting from normal operating conditions, is modelled with the objective of assessing the extent of the flammable cloud and the temperature evolution in the valve. 
 

Some functionalities of this simulation cannot be achieved without resorting to a Java macro (at least with versions up to v2021.1 when this KB was written):
  • Switching from Steady to Transient
  • Initializing Solver and Stopping Criteria
  • Changing the type of Interface from Baffle to Internal to model the valve aperture
The picture below shows the Simulation Operation pipeline, highlighting the use of Java macros.
 
A picture containing text  Description automatically generated

Note that we preferred to split the macros into elementary functionalities, such that each macro is very short and easy to read and maintain (possibly substituting it with an integrated functionality of the code if and when it becomes available).
 
Graphical user interface, text, application  Description automatically generated

The attached zip file contains the valve example together with all the macros needed to run it. This takes about 10 minutes on an 8-core machine.

Update (07/01/2022):
You can now take advantage of the functionality "Play Through Here" by using a Tag called "STOP" and assigning it to the last Simulation Operation Block you want to be executed.

Update (05/06/2023):
The macro now looks up the java files in both the macro folder (first choice) and the Simulation folder (second choice). This can be useful in certain circumstances for batch runs on clusters.

 

KB Article ID# KB000045968_EN_US

Contents

SummaryDetails

Associated Components

Design Manager Electronics Cooling In-Cylinder (STAR-ICE) Job Manager Simcenter STAR-CCM+