Running Multiple Simulations Consecutively

You can load and run multiple simulation files consecutively using a single macro. You do not need a separate shell or DOS script.

The following sample macro looks for all the .sim files in a specified directory, then for each simulation file it starts a server, iterates, and saves to a new filename. Starting new simulations requires the appropriate licenses.

// STAR-CCM+ macro: runMultiple.java
package macro;
import java.io.*;
import star.base.neo.*;
import star.common.*;
public class runMultiple extends StarMacro {
  public class SimFileFilter implements FilenameFilter {
    public boolean accept(File dir, String name) {
      return name.endsWith(".sim");
    }
  }
  public void execute() {
    File simDir = new File("c:\\users\\john\\documents\\testMultiple");
    Simulation sim_0 = getActiveSimulation();
    sim_0.kill();
    for (File f : simDir.listFiles(new SimFileFilter())) {
      startAndRun(f);
    }
  }
  public void startAndRun(File f) {
    System.out.println("\n Starting "+f);
    String fileName = f.getAbsolutePath();
    Simulation sim = new Simulation(fileName);
    // Uncomment next line to clear simulation before running
    // sim.getSolution().clearSolution();
    sim.getSimulationIterator().run();
    String newFileName = fileName.replaceAll("\\.sim","-new.sim");
    sim.saveState(newFileName);
    sim.kill();
  }
}

To use the sample macro:

  1. Save the macro to a Java file and name it runMultiple.java.
  2. In the macro, provide the correct path to the working directory. That is, replace "C:\\users\\john\\documents\\testMultiple" with the path to the actual working directory. The working directory contains the simulation files to run in sequence.
  3. In the working directory, issue the following command:

    Windows:

    [INSTALL_DIR]\star\bin\starccm+ -batch runMultiple.java

    Linux:

    [INSTALL_DIR]/star/bin/starccm+ -batch runMultiple.java