Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet to show Pushover integration into a STAR-CCM+ Java macro.
/**
* This is the main method in the macro. It is executed when the macro is
* run in STAR-CCM+.
*/
public void execute() {
try {
// Find the current simulation
Simulation theSim =
getActiveSimulation();
// Set up DataReader
DataReader reader =
new DataReader();
// Read from input file; populate list with SimData objects
reader.readInput(folder + "/trainInput.txt");
// Reference to list of SimData objects (to simplify later steps)
List<SimData> listCases =
reader.getFlowDetails();
// Set up DataWriter (this creates the output file and writes headings)
DataWriter writer =
new DataWriter(folder + "/trainOutput.txt");
// Set up Simrunner (retrieves various objects from the sim which will be set)
SimRunner runner =
new SimRunner(theSim);
// Set up PostProcessor (retrieves scenes and plots which will be saved)
PostProcessor postP =
new PostProcessor(theSim);
// Set up PushoverClient (sends notifications to the smartphone)
PushoverClient client =
new PushoverRestClient();
// The following construct is a "for-each" loop...
for (SimData sD : listCases) {
// Print line to output window to show how far the process has reached
theSim.println("Inside the loop. Running case with angle " + sD.getAngle());
client.pushMessage(PushoverMessage
.builderWithApiToken("APP_TOKEN")
.setUserId("USER_KEY")
.setTitle("Starting case.")
.setMessage("Inside the loop. Running case with angle " + sD.getAngle())
.build()
);
// Set various conditions, clear previous solution, run simulation for x iterations
runner.runCase(sD, 5);
// Retrieve the drag coefficient from the SimData object and write it to file
writer.writeDataLine(sD);
// Save hardcopies of vel mag and streamlines scenes, and residual plot
postP.saveVelMagScene(
folder + "/velMag" + sD.getAngle() + ".png"
);
postP.saveResidualPlot(
folder + "/residuals" + sD.getAngle() + ".png"
);
postP.saveStreamlinesScene(
folder + "/strlines" + sD.getAngle() + ".sce"
);
// Save simulation
theSim.saveState(
folder + "/train" + sD.getAngle() + ".sim"
);
// Send notification
client.pushMessage(PushoverMessage
.builderWithApiToken("APP_TOKEN")
.setUserId("USER_KEY")
.setTitle("Stopping case.")
.setMessage("Stopping criteria for case 'train" + sD.getAngle() + "' reached.")
.build()
);
}
} catch (Exception e) {
// Included for debugging, create a window displaying the error message
JOptionPane.showMessageDialog(
null, e.toString()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment