As mentioned earlier, the recording and writing of STAR-CCM+ macro files are essentially Java files, so it can be developed and debugged using Java programming methods. If complex business scenarios are involved, additional functions need to be added. The program itself is relatively complex, and it is difficult to wait until the entire program is written before testing it. It is inevitable to debug during the development process. The development tool used by the official document is the old version of NetBeans. Many functions have changed. In addition, the official document description is too simple. Most people are still confused about the debugging process of STAR-CCM+ after reading it.VSCode As a leader in emerging IDE, you can not only support Java programming through expansion, but also copilot To expand the integrated powerful AI programming capabilities, this article uses VSCode to demonstrate the debugging process of STAR-CCM+ macro files.

1. VSCode configuration

First of all, you need to install the Java extension in VSCode, and at least the following must be installed:

  1. Language Support for Java(TM) by Red Hat
  2. Debugger for Java
  3. Project Manager for Java

You can also install this expansion package directly and install all the Java expansions you need at one time:Extension Pack for Java

Download a JDK and install it. If you don’t want to download the JDK, you can also find the JDK that comes with the installation package in the STAR-CCM+ installation path and add it to the environment variables.

53d9d7c07aca055269657c5ccf18a81f.png

2. Create a Java project

Enter in the VSCode command panel (Ctrl+Shift+P) Java: Create Java Project, create a new java project.

56a3e9ec89aa1f165d0bbf43818f8843.png

Project type selection No build tools .

e3fe06a5c9f45db8e2bb95dd2229afb3.png

In the pop-up dialog box, select the project folder location, and then enter the project name (for example: starccm), and the new project is completed, you can see the structure of the java project.

4f796690032a038647929f935871897e.png

Copy the [STAR-CCM+_Installation]/star/lib/java/platform/modules/ext folder to the lib folder of the new project1.

6ee3b58e9ea5f952aef77f34dccd5a18.png

Copy the previously recorded or written java macros to the java file generated by the project. You can see that the syntax check and code highlighting prompts have taken effect. At this time, modifying the code can automatically complete the supplementary code snippet, or you can call copilot to automatically fill in and correct code errors through Ctrl+I.

de9b21474ee4bb138a6ada6e449eefb9.png

3. Configuration debugging

In the project folder .vscode Modify in the directory launch.json File, edit code as follows.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Attach)",
            "projectName": "starccm",
            "request": "attach",
            "hostName": "localhost",
            "port": 8765
        }
    ]
}

if .vscode No below launch.json This file can be clicked on the left side of VSCode运行与调试button, generate the file according to the prompts, and edit it as above.

fe42c7df2354ce038014d8fab7610fd6.png

Start the STAR-CCM+ main program through the command line, be careful to starccm+ The startup parameters are attached later. address The port number behind should be as above launch.json The port numbers filled in the file are the same.

<InstallationDirectory>/star/bin/starccm+ -jvmargs '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8765'

9d3195c2a43a1987c82be84179648cd9.png

After the above configuration is completed, you can open or create a new sim file in STAR-CCM+ to test the java program we wrote.

Then click on the left side of VSCode 运行与调试 button to enter debug mode. After successfully entering debug mode, the call stack and breakpoint information will be displayed on the modulation page.

77e492c6e2f6b2b11616ee8b5074332d.png

If you fail to enter debug mode, a dialog box will pop up. It is necessary to confirm whether STAR-CCM+ has normal startup, whether there are additional startup parameters, and launch.json Is there any error in writing the file?

d917ee07dd6acd9fb56eaa4168bed927.png

4. Debugging process

Below is a simple java file to demonstrate the debugging process.

// The following line is automatically generated during recording. It has no effect and can be commented out.
// package macro;

import star.common.*;

public class testCCMDebug extends StarMacro {

  // Macro operation entry
  public void execute() {
    pringMsg();
  }

  // Demonstrates the function of printing messages
  private void pringMsg() {
    Simulation simulation_0 = getActiveSimulation();
    simulation_0.println("Hello, starccm+!");
    simulation_0.println("This is a macro example.");
    simulation_0.println("This macro is used to test STAR-CCM+ debug mode.");
    String fileName = simulation_0.getPresentationName() + ".sim";
    simulation_0.println("The simulation file name is: " + fileName);
  }

}

Then add breakpoints to it.

41ef0c76c1932fe320359a8e84dad63f.png
c4a225cbb85bb7496366d8687c44f7ee.png

The key point is 2, Be sure to use “play macro” to load the java file in STAR-CCM+ . When the execution reaches a breakpoint, an interrupt will be prompted in VSCode, so that the debugging execution process can be controlled through VSCode.

5aac9b5a398c7733e445025ae69624da.png

Final execution effect:

9b5db179b2483fe30352d7bb840cfe77.png

The debugging execution reaches a breakpoint, and STAR-CCM+ will enter a pause state during the process. At this time, clicking the Cancel button (the red X next to the progress bar) is useless.

ed8fa3bd5401c2c409ca23368d142cc2.png

After the VSCode debugging is completed, if you want to enter debugging again, you need to use “play macro” in STAR-CCM+ to reload the java file.