CFD Online Discussion Forums

CFD Online Discussion Forums (
-   STAR-CCM+ (
-   -   Java code to get the current time/iteration step (

varoon April 26, 2010 05:40

Java code to get the current time/iteration step
I am writing a macro code to change a parameter value in ccm. I require current iteration no or time step. Is it possible to acess this data in JAVA macro code?

kyle April 26, 2010 10:12

This will return an integer with the current iteration number...

getActiveSimulation().getSimulationIterator().getC urrentIteration()

varoon April 26, 2010 23:39

Thanks a lot!.. I am trying to update a parameter based on the change in timestep when the simulation is running..

I used simulation_0.getSimulationIterator().run();.. a simple example to my problem is given below:


if ( simulation_0.getSimulatorIterator().getCurrentTime step() >2)
{vel = 24;

After the entire run is over, it checks the if loop. and not during the run.. Is there any way to change the parameter during the run.

I tried recording a macro to see if the change in the value is recorded during the run.
It does get recorded only after the simulation_0.getSimulationIterator().run();
Do u have any suggestions?

jopawipr June 1, 2010 11:56

have you solved your problem?
cause i have a quite similar one.

int TimeStepNumber = simulation_0.getSimulationIterator().getCurrentTim eLevel()

if(TimeStepNumber %3 == 0) {
MeshPipelineController meshPipelineController_0 = simulation_0.get(MeshPipelineController.class);

So i wana remesh my mesh every third time-step.
but it doesn't work.
The simulation is just running without remeshing...

thanks a lot!

kyle June 1, 2010 12:38

If you want to remesh every 3 timesteps, then do this...


public void execute() {

    Simulation sim = getActiveSimulation();

    // run three timesteps

    // remesh

    // repeat


varoon June 1, 2010 23:39

yeah.. I used simulation_0.getSimulationIterator().run(1); It stops after every iteration. Then i changed the parameter and ran again.

I think (as stated by Kyle) sim.getSimulationIterator().step(3); must work for you.

jopawipr June 2, 2010 09:14

thanks a lot!
so the simulation is running,
but there is no remeshing...

in the output window i can read that message:

Stopping criterion Maximum Inner Iterations satisfied.
Initializing meshing pipeline...
No initialization required.
Executing surface meshers...
Surface remesher up to date, skipping...
All volume meshers up to date, skipping...

so what's wrong? :confused:

thank you for your help!!

kyle June 2, 2010 09:38

jopawipr, why are you remeshing? If no settings have changed in the mesher, and the input surface has not changed, then the meshers will all skip. There is no reason to mesh when it would just result in the same mesh that you already have!

jopawipr June 2, 2010 09:44

sorry, my explination was not exact enough...

I've a moving mesh.
The simulation is running well until a certain time-step.
Than the mesh is to bad and the simulation breaks down.
So i thought it's possible to remesh(with the same mesh values) the mesh during the simulation after 5, 10 or maybe 100 time steps, cause the geometry changes during the simulation

ems June 2, 2010 09:56

In case you needed to extract the time (instead of the iteration), you could also generate an Expression report with a definition of $Time and then extract this value in your java code, such as:

ExpressionReport expressionReport_0 =
((ExpressionReport) simulation_0.getReportManager().getReport("TimeChe ck"));

(my report was named TimeCheck)


ryancoe June 21, 2010 09:09

I had this problem for a while, but seem to have found the solution...

You need to use:

simulation_0.getSimulationIterator().run(1, true);

This will run the simulation for one time-step (or iteration if you are doing a steady-state), and wait for iterating to complete before attempting to continue the macro. The Boolean "true" forces the macro to wait. If you look in the JAVA API, you'll find an explanation of this, although I must admit as a novice java programmer I find the API pretty cryptic.

Hope that helps,


All times are GMT -4. The time now is 11:58.