After recording the macro, it is good practice to open the file and noting which statements correspond to which actions.
To add notes to the Java file type
//"and your comment" . The following steps examine the initial macro and describe which statements correspond to the actions you recorded in the previous section.
Open the
macroRecording.java file in an appropriate text editor. Refer to the first section of the Java macro. The first set of statements in the macro conforms to the template of a standard
Simcenter STAR-CCM+ macro.
Code
|
Explanation
|
// STAR-CCM+ macro: macroRecording.java
package macro;
import java.util.*;
import star.common.*;
import star.base.neo.*;
import star.vis.*;
import star.base.report.*;
import star.flow.*;
public class macroRecording extends StarMacro {
public void execute() {
execute0();
}
private void execute0() {
|
- The class is defined as belonging to the
macro package.
- A number of libraries are imported which are required to compile the macro.
- A class called
macroRecording is declared, and is specified as a subclass of the
StarMacro class.
- The main method,
execute() , is declared. When the macro is played in
Simcenter STAR-CCM+ it uses
execute() , which calls
execute0() .
|
Look at the body of statements that were added to the macro during the record operation. Examine the body of the
execute0() method. Find each statement as it is described, and add a comment in the text editor to describe its function.
Code
|
Explanation
|
Simulation simulation_0 =
getActiveSimulation();{
|
- This statement is essential for STAR-CCM+ macros that interact with and manipulate a simulation. A variable of type
Simulation is declared, called
simulation_0 . A reference to the location of the active simulation object is obtained using the
getActiveSimulation() method and stored in the
simulation_0 variable. Add the comment: "// Retrieve the current simulation".
|
PhysicsContinuum physicsContinuum_0 =
((PhysicsContinuum) simulation_0
.getContinuumManager()
.getContinuum(“Physics 1”)
);
VelocityProfile velocityProfile_0 =
physicsContinuum_0
.getInitialConditions()
.get(VelocityProfile.class);
velocityProfile_0
.getMethod(ConstantVectorProfileMethod.class)
.getQuantity()
.setComponents(-10.0, 10.0, 0.0);
|
- These statements set the initial velocity. Setting values using a macro follows the same logical sequence as expanding nodes in the object tree. First you find the physics continuum
Physics 1 in the active simulation,
simulation_0 , and you store a reference to its location in the variable
physicsContinuum_0 . Then you look in
physicsContinuum_0 for the initial velocity condition, and store a reference to its location in
velocityProfile_0 . Finally you set the new velocity condition using the
setComponents() method.
|
Each of the entities in
Simcenter STAR-CCM+ is an object, for example boundaries, continua and even the active simulation. To interact with such objects, such as setting a constant value, methods exist which allow you to locate the object in question. To locate an object, follow the hierarchy of the object tree. For example, the initial velocity object is contained in a physics continuum object, which is contained in a simulation object. To interact with such an object, create a variable of the relevant type to store a reference to the location of the object.
Code
|
Explanation
|
Region region_0 =
simulation_0
.getRegionManager()
.getRegion(“trainAndTrack”);
Boundary boundary_0 =
region_0
.getBoundaryManager()
.getBoundary(“Inflow”);
VelocityProfile velocityProfile_1 =
boundary_0
.getValues()
.get(VelocityProfile.class);
velocityProfile_1
.getMethod(ConstantVectorProfileMethod.class)
.getQuantity()
.setComponents(-5.0, 5.0, 0.0);
|
- Here you set the inflow velocity. Find the
trainAndTrack region in the active simulation, then find the
Inflow boundary within that region, the
Velocity condition within that boundary, and finally set the new velocity. To find the region you use a
RegionManager , and to find a boundary in the region you use the
BoundaryManagerbelonging to that region. A second variable of type
VelocityProfile has been created and has been numbered incrementally to
1.
|
Solution solution_0 =
simulation_0
.getSolution();
solution_0.clearSolution(Solution.Clear.History, Solution.Clear.Fields, Solution.Clear.LagrangianDem);
|
- These statements retrieve any solution belonging to the current simulation and clear it by calling the
clearSolution() method.
|
ResidualPlot residualPlot_0 =
((ResidualPlot) simulation_0
.getPlotManager()
.getObject(“Residuals”)
);
|
- This set of statements precedes the run simulation command, creating a
Residuals plot in which to display the simulation progress.
|
simulation_0.getSimulationIterator().runAutomation();
|
- This statement is used to run the simulation.
|
Code
|
Explanation
|
ForceCoefficientReport forceCoefficientReport_0 =
((ForceCoefficientReport)
simulation_0.getReportManager()
.getReport(“Drag Coefficient”)
);
forceCoefficientReport_0.printReport();
|
- Here you find the drag coefficient report, and store a reference to its location in the variable
forceCoefficientReport_0 . The
printReport() method is then used to run the report within
Simcenter STAR-CCM+. You can use various alternative methods here, for example
getReportMonitorValue() - this yields the value of the drag coefficient.
|
Scene scene_0 =
simulation_0
.getSceneManager()
.getScene(“Velocity Magnitude”);
CurrentView currentView_0 =
scene_0
.getCurrentView();
currentView_0.setInput(
new DoubleVector(
new double[]{-2.37, -46.74, -5.45}
), new DoubleVector(
new double[]{-2.37, -46.74, 152.76}
), new DoubleVector(
new double[]{0.0, 1.0, 0.0}
), -1.0, 0
);
scene_0.printAndWait(
resolvePath(“/myTutorials/velMag.png
), 1, 1024, 768
);
|
- This set of statements was generated when the hardcopy of the
Velocity Magnitude scene was saved. The first statement finds the scene and assigns it to the variable
scene_0 . The lines that follow set the current view of the scene, however they are not necessary in this case and can be removed. The next statement uses the
printAndWait() method to print the image to file. Notice that the resolution 1024x768 that was entered when the macro was recorded is included in this statement.
|
residualPlot_0.encode(
resolvePath(“/myTutorials/res.png”
), “png”, 1024, 768
);
|
- This set of statements is used to save a copy of the
Residuals plot.
|
Scene scene_1 =
simulation_0
.getSceneManager()
.getScene(“Streamlines”);
scene_1.open(true);
scene_1.export3DSceneFileAndWait(
resolvePath(“/myTutorials/streamlines.sce”
), true
);
|
- Here you save a STAR-View+ scene file of the
Streamlines scene by using the
export3DSceneFileAndWait() method.
|
simulation_0.saveState(
resolvePath(“/myTutorials/trainMacro.sim”)
);
|
- Finally, the simulation is saved under the name
trainMacro.sim.
|
To quickly find what you need when writing the final macro, add comments above each statement or set of statements at this stage.
Save the
macroRecording.java file.