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

how to stop the solver from continuing the solution

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2021, 14:55
Question how to stop the solver from continuing the solution
  #1
New Member
 
Hamed Hoorijani
Join Date: May 2019
Posts: 13
Rep Power: 5
Hamedhoorijani is on a distinguished road
Hi everyone
I'm doing research on adding state-space trajectory and hopefully use it to speeding up the solution.
At some point in the "while (runTime.run())" loop, I need to define a condition and tell the algorithm if the condition is satisfied stops the solution, and read some data.
I'm having a hard time finding how should I tell the algorithm to stop the solution. Is there a specific function to do so? or stop a specific parameter to terminate the solution?
I'll be grateful if you could guide me.
Thanks
Hamedhoorijani is offline   Reply With Quote

Old   July 21, 2021, 15:42
Default
  #2
Member
 
Join Date: Mar 2021
Posts: 38
Rep Power: 3
trailer is on a distinguished road
Quote:
Originally Posted by Hamedhoorijani View Post
Hi everyone
I'm doing research on adding state-space trajectory and hopefully use it to speeding up the solution.
At some point in the "while (runTime.run())" loop, I need to define a condition and tell the algorithm if the condition is satisfied stops the solution, and read some data.
I'm having a hard time finding how should I tell the algorithm to stop the solution. Is there a specific function to do so? or stop a specific parameter to terminate the solution?
I'll be grateful if you could guide me.
Thanks

Hi,
Will this be helpful? https://www.openfoam.com/documentati...e-control.html

Last edited by trailer; July 21, 2021 at 17:51.
trailer is offline   Reply With Quote

Old   July 22, 2021, 15:56
Default
  #3
New Member
 
Hamed Hoorijani
Join Date: May 2019
Posts: 13
Rep Power: 5
Hamedhoorijani is on a distinguished road
Hi,
Thanks a lot for your reply.
That actually helped a lot, Thanks.
But what I'm looking for is a way to stop the solution inside the solver. I want to define my condition inside the solver's source code and then I could continue my work from there.
I want to write this function object's code inside the solver, so I could stop the solution without crashing the job and I could do other calculations. what I don't know is what parameter or function should I stop or call to do inside the source code?
Hamedhoorijani is offline   Reply With Quote

Old   July 22, 2021, 18:42
Default
  #4
Member
 
Join Date: Mar 2021
Posts: 38
Rep Power: 3
trailer is on a distinguished road
Quote:
Originally Posted by Hamedhoorijani View Post
Hi,
Thanks a lot for your reply.
That actually helped a lot, Thanks.
But what I'm looking for is a way to stop the solution inside the solver. I want to define my condition inside the solver's source code and then I could continue my work from there.
I want to write this function object's code inside the solver, so I could stop the solution without crashing the job and I could do other calculations. what I don't know is what parameter or function should I stop or call to do inside the source code?
Will this help you?


Code:
        bool exitFlag (false);
        label iterationCounter (0);
        label maxNumberOfIterations (5); // Set this to some number you feel confortable with

        while ( (!exitFlag) && (iterationCounter < maxNumberOfIterations) )
        {
      // Calculations go in here

        iterationCounter += 1;


              if (myConvergenceCriteriaHasBeenReached)
            {
                exitFlag = true;
            }

            if( (iterationCounter == maxNumberOfIterations) && (!exitFlag) )
            {
                Info << "Solver did not converge in: " << iterationCounter << " iterations " << endl;
            }
        }
trailer is offline   Reply With Quote

Old   July 23, 2021, 07:03
Default
  #5
New Member
 
Hamed Hoorijani
Join Date: May 2019
Posts: 13
Rep Power: 5
Hamedhoorijani is on a distinguished road
Thanks for your reply
Yes, That's actually what I'm looking for. Thank you.
but can I use it as :

Code:
while ((runTime.run()) && (!exitFlag))
?

Instead of using the (iterationCounter < maxNumberOfIterations) I use the runTime.run() of the solver?
Hamedhoorijani is offline   Reply With Quote

Old   July 24, 2021, 18:11
Default
  #6
Member
 
Join Date: Mar 2021
Posts: 38
Rep Power: 3
trailer is on a distinguished road
Quote:
Originally Posted by trailer View Post
Will this help you?


Code:
        bool exitFlag (false);
        label iterationCounter (0);
        label maxNumberOfIterations (5); // Set this to some number you feel confortable with

        while ( (!exitFlag) && (iterationCounter < maxNumberOfIterations) )
        {
      // Calculations go in here

        iterationCounter += 1;


              if (myConvergenceCriteriaHasBeenReached)
            {
                exitFlag = true;
            }

            if( (iterationCounter == maxNumberOfIterations) && (!exitFlag) )
            {
                Info << "Solver did not converge in: " << iterationCounter << " iterations " << endl;
            }
        }

Just a note, I do not know if you need to do any changes to run this in parallel!
trailer is offline   Reply With Quote

Old   July 25, 2021, 13:09
Default
  #7
New Member
 
Hamed Hoorijani
Join Date: May 2019
Posts: 13
Rep Power: 5
Hamedhoorijani is on a distinguished road
Thanks for the warning, I don't know about this code I haven't used the bool type variable in my codes.

I added other mathematical functions to OpenFOAM's solvers and it didn't bothered me as long as I wrote them using "foam" namespace. MPI and parallelization wasn't a problem so far for me.
Hamedhoorijani is offline   Reply With Quote

Reply

Tags
openfoam 7, programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
foam-extend-4.1 release hjasak OpenFOAM Announcements from Other Sources 19 July 16, 2021 05:02
Buoyancy-driven flow eclipsed by solver noise? JayDeeUU OpenFOAM Running, Solving & CFD 0 March 7, 2021 16:53
SU2 7.0.7 Built on CentOS 7, parallel computation pyscript mpi exit error? EternalSeekerX SU2 3 October 9, 2020 18:28
Working directory via command line Luiz CFX 4 March 6, 2011 20:02
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 02:58


All times are GMT -4. The time now is 23:39.