CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   how to check when the residual is smaller than the prescribed tolerance while solving (https://www.cfd-online.com/Forums/openfoam-solving/182394-how-check-when-residual-smaller-than-prescribed-tolerance-while-solving.html)

6863523 January 9, 2017 04:04

how to check when the residual is smaller than the prescribed tolerance while solving
 
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

t.oliveira January 9, 2017 18:47

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

6863523 January 11, 2017 02:23

steady flow
 
1 Attachment(s)
Quote:

Originally Posted by t.oliveira (Post 632626)
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

6863523 January 12, 2017 03:43

tolerance and convergence in fvSolution
 
1 Attachment(s)
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: https://www.cfd-online.com/Forums/op...tions-0-a.html
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

jeytsav January 12, 2017 05:15

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 January 12, 2017 10:20

Quote:

Originally Posted by jeytsav (Post 632969)
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

jeytsav January 12, 2017 15:43

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

6863523 January 13, 2017 02:04

error while using the residualControl
 
1 Attachment(s)
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

6863523 January 15, 2017 04:37

simulations will not stop using convergence
 
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

jeytsav January 15, 2017 05:31

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

6863523 January 15, 2017 08:50

results checked
 
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

jherb January 18, 2017 12:57

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;
          }


    }
}


6863523 January 18, 2017 13:11

Quote:

Originally Posted by jherb (Post 633783)
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.
https://www.cfd-online.com/Forums/op...ning-most.html
Thank you in advance.
Best Regards,
Bill

jherb January 19, 2017 05:38

Are you sure, that you need such tight tolerance levels? Normal values seems to be in the range of 1e-4.

6863523 January 19, 2017 10:22

Quote:

Originally Posted by jherb (Post 633862)
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 January 20, 2017 03:03

residualControl not work
 
1 Attachment(s)
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

jherb January 20, 2017 18:57

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: https://www.cfd-online.com/Forums/op...tml#post633783

6863523 January 21, 2017 14:53

residualControl still not work
 
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: https://www.cfd-online.com/Forums/op...ls-ending.html

I have no clue to do what for the next step...
Yours sincerely,
Bill

6863523 January 22, 2017 11:03

residualControl for pimpleFoam
 
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

alexeym January 23, 2017 02:03

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.


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