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

how to check when the residual is smaller than the prescribed tolerance while solving

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 9, 2017, 04:04
Smile how to check when the residual is smaller than the prescribed tolerance while solving
  #1
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear,
I have set the tolerance for U and p separately, and how can I realize automatically that the simulation will stop once the residuals for both U and p are smaller than the corresponding predefined tolerance?

Thank you for any help.
Best Regards,
Bill

Last edited by 6863523; January 22, 2017 at 11:18. Reason: delete sth unrelated
6863523 is offline   Reply With Quote

Old   January 9, 2017, 18:47
Default
  #2
Senior Member
 
Thomas Oliveira
Join Date: Apr 2015
Posts: 114
Rep Power: 12
t.oliveira is on a distinguished road
Bill,

I don't know which solver your are using, but consider the SIMPLE for example. Look at the source code of Foam::simpleControl::criteriaSatisfied().
I understand from it that the convergence is achieved just when the residuals of all fields are less then the values that were set for each one. That is, it is doing already what you wanted it to do.

Best regards,
Thomas
t.oliveira is offline   Reply With Quote

Old   January 11, 2017, 02:23
Smile steady flow
  #3
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Quote:
Originally Posted by t.oliveira View Post
Bill,

I don't know which solver your are using, but consider the SIMPLE for example. Look at the source code of Foam::simpleControl::criteriaSatisfied().
I understand from it that the convergence is achieved just when the residuals of all fields are less then the values that were set for each one. That is, it is doing already what you wanted it to do.

Best regards,
Thomas
Dear Thomas,
Thanks for the answer.
I compiled a new solver, a similar one to icoFoam. I agree with you that the solution is converged if the residuals are less than the prescribed tolerances.
I am confused while I am reading one paper, " From steady to unsteady laminar flow in model porous structures: an investigation of the first Hopf bifurcation", the part talking about the residual and the tolerance is attached. Because it seems that the author used the relation between them to judge whether the flow is steady or not at a certain Re.
I am confused whether the criteria for the convergence could be used to determine the flow is steady or not.
Thank you.
Best Regards,
Bill
Attached Images
File Type: jpg steady.jpg (69.1 KB, 53 views)
6863523 is offline   Reply With Quote

Old   January 12, 2017, 03:43
Default tolerance and convergence in fvSolution
  #4
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Hi,
I have set the tolerance for p and U separately in fvSolution file, as shown below.
Code:
solvers
{
    p
    {
        solver          PCG;
        preconditioner  DIC;
        tolerance       1e-07;
        relTol          0;
    }

    U
    {
        solver          PBiCG;
        preconditioner  DILU;
        tolerance       1e-10;
        relTol          0;
    }
}

PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;
}
I have searched throught the forum and found a post about setting the convergence creteria to stop the simulation at: Extrusion with OpenFoam problem No. Iterations 0
The related part about the convergence in the post is also screenshotted and attached.
I want to set the convergence separately for p and U. How can I realize this in the fvSolution file? I just add the convergence in the PISO content? If so, how can I add different values for p and U?
Thank you in advance.
Best Regards,
Bill
Attached Images
File Type: jpg convergence.jpg (14.7 KB, 37 views)
6863523 is offline   Reply With Quote

Old   January 12, 2017, 05:15
Default
  #5
Member
 
jey
Join Date: Nov 2016
Location: Greece
Posts: 30
Rep Power: 9
jeytsav is on a distinguished road
Dear Bill

Please correct me If I haven't understood correctly but what you are trying to do is setting residuals controls separately for pressure and velocity.

You can do this by simply including the following code in the fvSolution file

Code:
PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;

    residualControl
    {
        p               1e-5;
        U               1e-3;
    }

}

Kind regards!
6863523 likes this.
jeytsav is offline   Reply With Quote

Old   January 12, 2017, 10:20
Default
  #6
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Quote:
Originally Posted by jeytsav View Post
Dear Bill

Please correct me If I haven't understood correctly but what you are trying to do is setting residuals controls separately for pressure and velocity.

You can do this by simply including the following code in the fvSolution file

Code:
PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;

    residualControl
    {
        p               1e-5;
        U               1e-3;
    }

}
Kind regards!
Dear jeytsav,
Thank you for your reply.
Yes! This is the first step I want to do. (To stop the simulation as long as the residuals are smaller than the tolerance.)

Code:
PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;

    convergence
    {
        p               1e-5;
        U               1e-3;
    }

}
There is a problem if I use residualControl, but if I use convergence, there is no problem, I am checking on if the command lines really work for my case. And I will let you know.
I am wondering about the second step if it is possible to check the flow is steady according to the convergence criteria.
Thank you.
Best Regards,
Bill
6863523 is offline   Reply With Quote

Old   January 12, 2017, 15:43
Default
  #7
Member
 
jey
Join Date: Nov 2016
Location: Greece
Posts: 30
Rep Power: 9
jeytsav is on a distinguished road
Dear Bill

I've been using residualControls with SIMPLE algorithm which is for steady-state simulations. Probably there must be a problem with this function when turning to transient solvers like PISO. Maybe a more experienced user can tell us why this happens.

Could you please post the error message that was produced when you tried it, just to gain further insight in OF functionality ? Which OF version are you using?

Regarding your second question, the author states that since the user prescribes the tolerances, is up to the user to set the threshold of the, lets say, "steadiness" of the flow.

So in our case, we state that when pressure residual reaches below 1e-5 and velocity residual reaches below 1e-3, the simulation has converged. The tolerances here are the 1e-5 and the 1e-3.
However, I think that wether a flow is steady or unsteady has nothing to do with that. I found this article explaining steady and unsteady flow.

I hope I helped

Please correct me if I am wrong!

Kind regards
jeytsav is offline   Reply With Quote

Old   January 13, 2017, 02:04
Smile error while using the residualControl
  #8
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear jeytsav,

The error while I am using the residualControl is like bellow.
Code:
 /*---------------------------------------------------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  3.0.1                                 |
|   \\  /    A nd           | Web:      [IMG]file:///C:\Users\wyb\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.png[/IMG]www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
Build  : 3.0.1-d8a290b55d28
Exec   : myIcoFoam
Date   : Jan 13 2017
Time   : 07:57:05
Host   : "srv-calmipo01"
PID    : 93231
Case   : /home/LEPT/ywang/OpenFOAM/ywang-3.0.1/run/UCUCUC/Re17500
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0



--> FOAM FATAL ERROR: 
Residual data for p must be specified as a dictionary

    From function bool Foam::solutionControl::read()
    in file cfdTools/general/solutionControl/solutionControl/solutionControl.C at line 84.

FOAM exiting
Q1: If I use the convergence criteria, the initial residuals will be compared to the tolerance or the convergence criteria?

Thank you for the article. It is very kind of you to help me.
I have read through the website, but did not find a clue on how to determine at which Re the flow will lose stability while using the transient solver.
The unsteadiness is related to the vortex shedding / oscillating streamlines, it is easy to observe these phenomena in a simple situation, like flow past a cylinder, at the same time, the lift coefficient or the component of velocity may be monitored to check the oscillating values with time, as attached, and also a related spectral analysis may be done.
Q2: But can these indications be just used to determine if the flow is steady or used only as auxiliaries?
I am confused and need help on this.
Thank you.
Best Regards,
Bill
Attached Images
File Type: jpg FFT.jpg (12.0 KB, 28 views)

Last edited by 6863523; January 13, 2017 at 02:41. Reason: not enough
6863523 is offline   Reply With Quote

Old   January 15, 2017, 04:37
Default simulations will not stop using convergence
  #9
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear jeytsav,
I added the lines in fvSolution, using
Code:
convergence
{p 1e-7;
U 1e-10;
}
However, it seems that the simulation will not stop until the "endTime=20000".
Code:
 Time = 20000.0000000443724
Courant Number mean: 0.125065 max: 0.342207
DILUPBiCG:  Solving for Ux, Initial residual = 2.61563e-13, Final residual = 2.61563e-13, No Iterations 0
DILUPBiCG:  Solving for Uy, Initial residual = 1.16709e-11, Final residual = 1.16709e-11, No Iterations 0
DICPCG:  Solving for p, Initial residual = 6.32159e-08, Final residual = 6.32159e-08, No Iterations 0
time step continuity errors : sum local = 7.58537e-14, global = -2.38405e-20, cumulative = -1.58064e-15
DICPCG:  Solving for p, Initial residual = 7.26257e-08, Final residual = 7.26257e-08, No Iterations 0
time step continuity errors : sum local = 8.71431e-14, global = -3.72906e-20, cumulative = -1.58068e-15
ExecutionTime = 170121 s  ClockTime = 170322 s

End
There is no iteration at all after a certain long time(after about time=4000, well before the endTime 20000), once the inital residual is smaller than the tolerance. I have checked the results, they are reasonable. The only problem is that the convergence criteria does not work at all, are these lines written in a wrong way? I want the simulations stop once all the inital residuals for p and U are smaller than the tolerances.
Thank you.
Best Regards,
Bill

Last edited by 6863523; January 15, 2017 at 08:22.
6863523 is offline   Reply With Quote

Old   January 15, 2017, 05:31
Default
  #10
Member
 
jey
Join Date: Nov 2016
Location: Greece
Posts: 30
Rep Power: 9
jeytsav is on a distinguished road
Dear Bill

Regarding the residual control I have found this thread that might solve the problem. Check the last post (post #7).


My approach to the problem would be to first solve as a steady-state case and then check whether the results agree (i.e. no oscillations) and if not, switch to a transient solver to have a better capture.

I think that the oscillation of force coefficients is a clear indication of unsteady flow as the field changes around the body with time. Actually I am not sure whether is correct to use the word "time" when talking about steady-state because it is time-independent. Maybe the word "pseudotime" is better.

Also note, that a flow might be unsteady in the beginning (so you will have oscillations) but then oscillations could be damped indicating a steady flow.

Kind regards
jeytsav is offline   Reply With Quote

Old   January 15, 2017, 08:50
Smile results checked
  #11
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear jeytsav,
Thank you very much for your quick help.
I have checked the results of the transient simulations. There is no oscillating streamlines, the same as for the steady solution.
In addition, I have monitored the component of velocity, and there is no peridic oscillation. Also, I have transformed the velocity component using FFT, and found there is only a signal at f=0.
Based on the above analysis, I assumed that the flow is still at steady for the Re range I have tested.
BTW: I have modified the fvSolution file according to the thread you recommended. I am testing and will post the results here.
It is really very kidn of you to help me so much. Thank you.
Best Wishes,
Bill
6863523 is offline   Reply With Quote

Old   January 18, 2017, 12:57
Default
  #12
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
Regarding your problem with the residual control: Which solver are you using? A solver based on PISO or on PIMPLE? If your solver is based on PIMPLE (e. g. pimpleFoam) you have to add something like the following to the PIMPLE section within system/fvSolution
Code:
PIMPLE 
{
// here are your other settings like nOuterCorrectors etc.

    residualControl
    {
          "(U.*)" // should also work for 2D problems
          {
                relTol          0;
                tolerance       1e-4;
          }

          p
          {
                relTol          0;
                tolerance       1e-4;
          }


    }
}
jherb is offline   Reply With Quote

Old   January 18, 2017, 13:11
Default
  #13
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Quote:
Originally Posted by jherb View Post
Regarding your problem with the residual control: Which solver are you using? A solver based on PISO or on PIMPLE? If your solver is based on PIMPLE (e. g. pimpleFoam) you have to add something like the following to the PIMPLE section within system/fvSolution
Code:
PIMPLE 
{
// here are your other settings like nOuterCorrectors etc.

    residualControl
    {
          "(U.*)" // should also work for 2D problems
          {
                relTol          0;
                tolerance       1e-4;
          }

          p
          {
                relTol          0;
                tolerance       1e-4;
          }


    }
}
Dear Dr Herb,
Thanks for your reply and the detailed information.
I am using icoFoam, based on PISO. But I would like to modify the fvSolution file according to your suggestions.
Code:
 PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;
    residualControl
    {
     p 
      { 
       relTol           0;
       tolerance    1e-07; 
      }
      U 
      { 
       relTol           0;
       tolerance    1e-10; 
      }

    }
}
The simulation needs a rather long time to reach the defined tolerance in order to test if the residualControl works or not.
I have posted the problem here and wonder if you have experience in running parallel.
How to use parallel running to the most?
Thank you in advance.
Best Regards,
Bill
6863523 is offline   Reply With Quote

Old   January 19, 2017, 05:38
Default
  #14
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
Are you sure, that you need such tight tolerance levels? Normal values seems to be in the range of 1e-4.
jherb is offline   Reply With Quote

Old   January 19, 2017, 10:22
Default
  #15
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Quote:
Originally Posted by jherb View Post
Are you sure, that you need such tight tolerance levels? Normal values seems to be in the range of 1e-4.
I set these values according to the paper (Agnaou et al., 2016), which I have mentioned in post #3. The values have been testified by the author.
And these values are the same ones for the solver as in post #4.
Thanks.
Regards,
Bill
6863523 is offline   Reply With Quote

Old   January 20, 2017, 03:03
Default residualControl not work
  #16
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear,
To update, I have run the case with the residualControl mentioned above, but it seems that it does not work al all. The simulation only ends according to the endTime in the controlDict file.
Thank you in advance for any suggestions.
Best Regards,
Bill
Attached Images
File Type: jpg result.jpg (58.3 KB, 20 views)
6863523 is offline   Reply With Quote

Old   January 20, 2017, 18:57
Default
  #17
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
Your solver solves for the fields Ux and Uy, so these names must appear in the PISO section of fvSolution. Otherwise these two fields are not checked, if they have converged. Please use the code from my first comment: how to check when the residual is smaller than the prescribed tolerance while solving
jherb is offline   Reply With Quote

Old   January 21, 2017, 14:53
Default residualControl still not work
  #18
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear jeytsav,
I have modified the fvSolution file according to your suggestions.
But it still does not work. The simulation only ends at the endTime, the residualControl function still does not work.
The fvSolution file is like this:
Code:
 FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
    p
    {
        solver          PCG;
        preconditioner  DIC;
        tolerance       1e-07;
        relTol          0;
    }

    U
    {
        solver          PBiCG;
        preconditioner  DILU;
        tolerance       1e-10;
        relTol          0;
    }
}
PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;
    residualControl
    {
     p 
      {
       relTol 0;
       tolerance 1e-07;
       }
     "(U.*)" 
      {
       relTol 0;
       tolerance 1e-10;
       }
    }
}
I have found a similar thread at this: Convergence/Residuals Ending

I have no clue to do what for the next step...
Yours sincerely,
Bill
6863523 is offline   Reply With Quote

Old   January 22, 2017, 11:03
Default residualControl for pimpleFoam
  #19
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear,
I have found an example, which uses the residualControl for pimple:
https://openfoamwiki.net/index.php/O...hm_in_OpenFOAM

And below is what I got from the openFoam support:

icoFoam is a simple demonstration solvers and does not and need not support residual control, fvOptions etc.

If you are developing an transient incompressible laminar or turbulent flow cases choose either pisoFoam or pimpleFoam if you need residual control, fvOptions etc.

Does this mean that the residualControl does not work for PISO algorithm? Thank you.
I am simulating the transient, laminar, incompressible flow.
Regards,
Bill

Last edited by 6863523; January 22, 2017 at 11:56. Reason: information added
6863523 is offline   Reply With Quote

Old   January 23, 2017, 02:03
Default
  #20
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

For residualControl to work nOuterCorrectors should be greater than 1. Since pisoFoam does not have outer correct loop (or in other words nOuterCorrectors is always 1), it does not check for convergence in term of initial residuals; pimpleFoam does.
frobaux likes this.
alexeym 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
a problem with convergence in buoyantSimpleFoam skuznet OpenFOAM Running, Solving & CFD 6 November 15, 2017 12:12
Wrong fluctuation of pressure in transient simulation caitao OpenFOAM Running, Solving & CFD 2 March 5, 2015 21:33
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
SLTS+rhoPisoFoam: what is rDeltaT??? nileshjrane OpenFOAM Running, Solving & CFD 4 February 25, 2013 04:13
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24


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