CFD Online Discussion Forums

CFD Online Discussion Forums (
-   STAR-CCM+ (
-   -   Error: Cycle detected in field function (

Rachit July 19, 2012 06:15

Error: Cycle detected in field function
Hi everyone,

I am carrying out a CFD analysis of a wind turbine. I want the turbine blades to rotating. The idea is to define a circular region around the blade which will be rotating at a certain angular velocity and will exchange data with the surrounding environment through a sliding mesh. Now, what I want is that angular velocity of the circular region be defined as:

w = 2.3559, for t <= 0.015s
w(t) = w(t - 1) + (Torque / Moment of Inertia)*TimeStep, for t > 0.015s

where Torque is the moment on the turbine blades.

for this i had defined a field function UserFieldFunction_1 defined as:

($Time <= 0.015) ? 2.3559 : $UserFieldFunction_1 + (($Torque/1.308)*0.005)
(moment of inertia is 1.308 kgm^2 and the time step is 0.005s)

however, following this i get the error message: "Warning: 1 cycle detected in function Turbine anglular velocity (UserFieldFunction_1)"

can anyone what am i doing wrong and how it can be rectified? i think its because of referencing the same field function in code, but then how else could such a function be defined?

Thanks in advance,

ryancoe July 19, 2012 10:19

If understand the logic that you're trying to use correctly, couldn't you use:

($Time <= 0.015) ? 2.3559 : 2.3559 + (($Torque/1.308)*0.005)

In your current implementation, when t > 0.015 the algorithm can never find a value of $UserFieldFunction_1 to use in the 2nd half of the statement.

Hope this helps,


Rachit July 24, 2012 04:48

Hi Ryan,

Thanks for replying. I shall be more clear of what I wish to accomplish, and correct me if I am wrong. I want the turbine to rotate with an angular velocity which is directly obtained from the equation:

Torque = I*alpha, where I is moment of inertia and alpha is the angular acceleration

that gives, alpha = Torque/I

now applying, euler's first order integration, we have

[(w(t) - w(t - 1))/delta T] = Torque/I

that gives me the relation mentioned in the previous post:
w(t) = w(t -1) + (Torque/I)*TimeStep

that is why I have to use the angular velocity from the previous time step. I understand what error I am getting, any idea how I can bypass it?


ryancoe July 24, 2012 08:26

I see... Sorry I misunderstood you before. I think that the easiest way to do this within Star-CCM+ (that is without using macros), would be to assign the value of w(t) to a table value, and then reference that value as well. I've never done this myself, but I'm pretty sure its possible (there's a section describing this sort of thing in the Help manual: "Working With Table Values Through Field Functions").

Alternatively, if you want to stay away from tables and just use an algorithm, you could write a java macro containing a for loop which creates and references the array w(t). The macro can then reassign the new w(t) value to a field function at every time step.


Rachit July 27, 2012 04:20

Dear Ryan,

I have been trying to figure out how to write a macro for this situation only to find myself extremely confused :confused:. This is my first macro so correct me if my approach is wrong. What I have been thinking is that I could record a macro in which I will change the field function definition as: [(2.3559 + (($Torque/1.308)*0.005))], following which I will run the simulation for 1 time step.
On recording this macro, I will change its java script by defining a variable temp which initially I will set it as 2.3559 and change the user field function definition as: [(temp + (($Torque/1.308)*0.005))], however, the value of temp has to be updated after every time step as temp = UserFieldFunction_1. I can then run the simulation for as many number of time steps by modifying simulation_0.getSimulationIterator().run().

Could you tell if this is possible or not? I have recorded the macro, but have little idea how to modify the java script. How can i update the term temp after every time step? Are there any guides available for scripting in Star CCM+? (There are very less examples in User Guide)

ryancoe July 27, 2012 11:19

If you've done any programming, editing and writing macros shouldn't be too hard. I would definitely suggest using an IDE like Netbeans or Eclipse. If you point theseIDEs to Star-CCM+'s packages, they can be really helpful.

There are 2 tutorials on Automation in the Help Manual that should give you a basic understanding of how things work.

I know this can be a bit daunting at first, but its worth your time.


abdul099 July 28, 2012 08:36

1 Attachment(s)
You don't even need to update the field function, you can try it with the attached macro. I couldn't upload a java file, so I renamed it to txt. Just change the file ending to java, and you can execute it in Star-CCM+.
I haven't tested the macro, but just try it and let us know when it doesn't work.

Rachit July 30, 2012 06:42


Thanks a lot! Your macro works just fine. I am getting the expected results.


All times are GMT -4. The time now is 21:29.