## General

#### How can I set up a repeating cycle of timesteps? For instance, I have a 0.03 second cycle where the timestep needs to get larger as the cycle progresses, but I want to go back to the original timestep at the start of the next cycle.

• FAQ
Participant

In CFX Expression language, the procedure is as shown below, but the logic would apply in any code. LIBRARY: CEL: &replace EXPRESSIONS: customtime = if(cycleno>1,Time-0.03[s]*(cycleno-1),Time) cycleno = int(Time/0.03 [s])+1 dt = if(cycletime <= 0.01[s] ,0.001[s], 0 [s])+ if(cycletime>0.01[s] && cycletime <= 0.02[s], 0.002[s], 0[s]) + if(cycletime >0.02[s] && cycletime<= 0.03[s], 0.003[s], 0.0[s]) END END END Since we have a repeating cycle of 0.03 [s], we need something to let us know what cycle we are in, so that we can make a custom time counter that will reset at the beginning of each cycle. This makes use of the int() function, which rounds UP to the closest integer. cycleno = int(Time/0.03 [s])+1 Next we can make a time counter that goes from 0-0.03 [s][ repeatedly. This makes use of the conditional if() function: cycletime = if(cycleno>1,Time-0.03[s]*(cycleno-1),Time) Now, we create a series of additive if() statements to cover each portion of the cycle. each one is only active inside its cycletime range dt = if(cycletime <= 0.01[s] ,0.001[s], 0 [s])+ if(cycletime>0.01[s] && cycletime <= 0.02[s], 0.002[s], 0[s]) + if(cycletime >0.02[s] && cycletime<= 0.03[s], 0.003[s], 0.0[s]) If the list is very long, create a separate if expression for each portion and then add these expressions for a tidier timestep expression that is easier to debug.