CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Provoking a clean exit from the main loop

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2006, 01:54
Default I am looking for a (simple) me
  #1
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
I am looking for a (simple) method to exit cleanly from the main calculation loop.
As pseudo-code:

for (runTime++; !runTime.end(); runTime++) {
solve_equations();
if ( isConverged() or user_signal())
{
runTime.writeNow() and exit_loop;
}
}

Looking through Time*.H, it would appear that something like altering the stop flag to 'saWriteNow' might do the trick, but I would really appreciate some pointers about the correct approach.

Thanks,
/mark
olesen is offline   Reply With Quote

Old   July 21, 2006, 04:25
Default You can create your own derive
  #2
Senior Member
 
Mattijs Janssens
Join Date: Mar 2009
Posts: 1,419
Rep Power: 26
mattijs is on a distinguished road
You can create your own derived Time class. All the main functions (specifically 'end()') are virtual.

Modifying the stop flag to saWriteNow will probably do the trick. It does require the operator++ to be executed though (since the time needs to be past the endTime) so will only stop at the start of the next loop.

Let us know how you solved it.
mattijs is offline   Reply With Quote

Old   July 21, 2006, 09:56
Default Hi Mattijs, Following your
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Hi Mattijs,

Following your tip, I tried my preferred solution, which resembled the following ...

bool Foam::myTime::writeAndEnd() const
{
stopAt_ = saWriteNow;
endTime_ = value();
outputTime_ = true;
return write();
}

After too many messages about fiddling with protected fields, I ditched this for the brute-force method:

loop (!runTime.end()) {
solve_equations();
bool written = runTime.write();

if ( isConverged() ) {
while (!written && !runTime.end()) {
written = (++runTime).write();
}
break;
}
}

This is certainly not elegant, but it does ensure that my data are written and the calculations stop.

I'll see about getting back to the 'proper' solution when I have more time. Perhaps it would even be useful enough to add back into the Foam::Time class?

Thanks,
/mark
olesen is offline   Reply With Quote

Old   July 25, 2006, 08:45
Default Hi Mattijs, I finally had a
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Hi Mattijs,

I finally had a few minutes more time and found the 'const' mistake. Attached is a version of myTime
myTime.tar.gz

that adds the following two member functions:

//- Write immediately
bool writeNow();

//- Write immediately and increment endTime to finish
bool writeAndEnd();

I left the copyright as "OpenCFD Ltd."

/mark
olesen is offline   Reply With Quote

Old   July 25, 2006, 10:14
Default Looks pretty good - thanks! I
  #5
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Looks pretty good - thanks! I have added it to the Time class.

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the case nameroot outside main normunds OpenFOAM Running, Solving & CFD 2 May 18, 2007 04:31
Main Diffenrences between commercian packages ?? Abou Main CFD Forum 8 October 16, 2006 08:36
axisymmetric main flow + injection Stephan FLUENT 1 January 19, 2006 11:43
loop(p,I->p) how this loop works? Sinan FLUENT 0 January 18, 2005 18:04
Main Star-CD Commands Maxime Perelli Siemens 1 April 17, 2001 08:35


All times are GMT -4. The time now is 02:01.