CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to stop the solver from continuing the solution (https://www.cfd-online.com/Forums/openfoam-programming-development/237519-how-stop-solver-continuing-solution.html)

Hamedhoorijani July 21, 2021 14:55

how to stop the solver from continuing the solution
 
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

trailer July 21, 2021 15:42

Quote:

Originally Posted by Hamedhoorijani (Post 808644)
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

Hamedhoorijani July 22, 2021 15:56

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?

trailer July 22, 2021 18:42

Quote:

Originally Posted by Hamedhoorijani (Post 808758)
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;
            }
        }


Hamedhoorijani July 23, 2021 07:03

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?

trailer July 24, 2021 18:11

Quote:

Originally Posted by trailer (Post 808767)
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!

Hamedhoorijani July 25, 2021 13:09

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.


All times are GMT -4. The time now is 00:14.