CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   runTime out of scope in functionObject (http://www.cfd-online.com/Forums/openfoam-programming-development/107155-runtime-out-scope-functionobject.html)

Sune September 19, 2012 03:22

runTime out of scope in functionObject
 
Hi all,

My situation: I have created a new functionObject by dublicating the existing forceCoeffs functionObject. I modified it to do various averaging functions on the fly, and check if forces have stabilized.

My problem: I want to writeAndEnd (or any equivalent) when a certain criteria is met, but runTime is not in scope.

Another problem: I am new to OF programming.

My setup: I'm running OF-2.1 in parallel, the layout of the code is much like the original forceCoeffs functionObject, so it includes Time.H. The code work as I intend and compiles when I do not include any runTime functions.

Question: I can access time information from the objectRegistry like obr_.time().timeName() but so far as I can see, it does not inherit the member functions I am interested in. Can I include runTime in the functionObject scope or is there another way I can write and stop simulation?

What I have tried so far:
Code:

runTime.writeAndEnd();
//produce the error: runTime is not in scope

and
Code:

obr_.time().writeAndEnd();
//produce the error: class has no member named writeAndEnd

and many more desperate variations.


My feeling is that my main problem is in my programming skills and that I am doing something embarisingly wrong, so I hope someone can give me a pointer to the right solution, thank you in advance.

gschaider September 24, 2012 17:30

Quote:

Originally Posted by Sune (Post 382480)
Hi all,

My situation: I have created a new functionObject by dublicating the existing forceCoeffs functionObject. I modified it to do various averaging functions on the fly, and check if forces have stabilized.

My problem: I want to writeAndEnd (or any equivalent) when a certain criteria is met, but runTime is not in scope.

Another problem: I am new to OF programming.

My setup: I'm running OF-2.1 in parallel, the layout of the code is much like the original forceCoeffs functionObject, so it includes Time.H. The code work as I intend and compiles when I do not include any runTime functions.

Question: I can access time information from the objectRegistry like obr_.time().timeName() but so far as I can see, it does not inherit the member functions I am interested in. Can I include runTime in the functionObject scope or is there another way I can write and stop simulation?

What I have tried so far:
Code:

runTime.writeAndEnd();
//produce the error: runTime is not in scope

and
Code:

obr_.time().writeAndEnd();
//produce the error: class has no member named writeAndEnd

and many more desperate variations.


My feeling is that my main problem is in my programming skills and that I am doing something embarisingly wrong, so I hope someone can give me a pointer to the right solution, thank you in advance.

Either dynamicCast the obr to be a fvMesh (which it actually is) or if you have a field use the mesh()-method of that to get to the same mesh

Sune September 26, 2012 02:11

Quote:

Originally Posted by gschaider (Post 383399)
Either dynamicCast the obr to be a fvMesh (which it actually is) or if you have a field use the mesh()-method of that to get to the same mesh

Thanks for your answer, I settled on the following solution:

Code:

obr_.time().stopAt(Time::saNextWrite)
the enumerator stopControls in Time.H also gives the other standard stopAt options with saNoWriteNow and saWriteNow.


All times are GMT -4. The time now is 07:17.