Finalizing the Structure of the Macro
It is good practice to finalize the macro structure before writing the final macro. Deciding how best to organize the macro, for example what methods to use, which actions to include in a loop, and the number of classes required. These decisions are based on necessity and your Java programming experience.
It is also useful at this stage to consider whether the macro needs to be modified in the future to include extra commands and processes, for example setting additional boundary conditions. If likely, it is recommended that the macro is divided into different subsections which carry out each task rather than having everything in a single continuous section. When you add extra processes to the macro, you can locate the section easily, and insert the command. The object-oriented nature of the Java language makes it suited to this kind of organization. In this tutorial, nested classes are used to distinguish between steps in the process.
The main processes are divided as follows:
- a class to read the input data
- a class from which to create objects which store input data
- a class to set values in Simcenter STAR-CCM+ and run the simulation
- a class to carry out post-processing tasks
- an additional class to write any data to an external file, for example the drag coefficient
These classes are given the following names, respectively:
- DataReader
- SimData
- SimRunner
- PostProcessor
- DataWriter
One key advantage in organizing the macro in this way is that the main method in the macro is easy to understand as the statements follow a logical sequence.
Using an Input Data File
Consider is how the macro reads the wind data and passed to the simulation. You want to be able to alter the data as required, and run as many simulations as necessary. For this reason, the input data is saved in a simple text file, and read into the simulation using the macro.
- Navigate to the automation folder of the downloaded tutorial files. Copy the trainInput.txt file to your working directory.
- Open the trainInput.txt file using an appropriate text editor.
The file contains the following data:
- the angle of attack of the cross-wind in degrees, AngDeg
- the velocity of the train, VelTrn
- the velocity of the cross-wind, VelWnd
- the corresponding initial velocities, InitVelTrn, and InitVelWnd
Each line in the file represents a set of data. Use the macro to read each line and store the data in an object. Store a collection of these objects in an array. When each simulation is run, the data is read from an object and passed efficiently to the simulation, without the need to reopen the input file.