Understanding the SimRunner Nested Class

In the SimRunner class, you implement the statements that were obtained when the macro was recorded.

Description Code
  • You declare the properties that are set in the simulation as member variables of the SimRunner class. Include only variables that are set using the input data, such as inlet velocity, and variables that are extracted, such as drag coefficient. The type of each of the member variables can be found by referring to the macroRecording.java file, and to the section Understanding the Recorded Macro .
private VelocityProfile m_inflowVel = null;
  • Locating an object in Simcenter STAR-CCM+ follows the same path as expanding nodes in the object tree. Therefore, to perform an operation such as setting the inlet velocity, locate each of the upper objects first. Here this action is performed in the constructor, as the location of the objects do not change, and you want to find the objects for every SimRunner object that is created.
  • The statements for locating each object can be copied from the recorded macro, taking care the change the variable names as necessary.
public SimRunner(Simulation theSim) {
 
  m_sim = theSim;
 
  PhysicsContinuum physics =
    ((PhysicsContinuum) m_sim
    .getContinuumManager()
    .getContinuum(“Physics 1”));
 
  m_initVel =
    ((VelocityProfile) physics
    .getInitialConditions()
    .get(VelocityProfile.class));
  
}
  • In the next method, runCase(), implement the statements that set the necessary properties in the simulation. First, you extract the values from the SimData object; then you use this data to set the values of each property. Notice that you use the getter methods that were defined in the SimData nested class to extract the data.
public void runCase(SimData sD, int iterations) {
 
  double initX =
    sD.getInitVelX();
  
  double velY =
    sD.getVelY();
Description Code
  • The variables are inserted into the x and y positions in the setComponents() method for the inflow and initial velocities; the variables have been underlined.
((ConstantVectorProfileMethod) m_initVel
  .getMethod())
  .getQuantity()
  .setComponents(initX, initY, 0.0);
 
((ConstantVectorProfileMethod) m_inflowVel
  .getMethod())
  .getQuantity()
  .setComponents(velX, velY, 0.0);
  • Each of the statements in the method is carried out in sequence. Once the new values have been set, you want to make sure that any previous solution has been cleared.
m_sim.clearSolution();
  • You can now run the simulation. The number of iterations is specified by passing an integer to the run() method, the value of which set when the runCase() method is called.
m_sim.getSimulationIterator()
  .run(iterations);
  • Finally, you obtain the drag coefficient, and store it in the SimData object by using the setter method defined earlier.
  double cdValue =
    m_forceReport.getReportMonitorValue();
 
    sD.setDrag(cdValue);
}

Proceed to the next section to examine the PostProcessor class.