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

[swak4Foam] transient convergence criteria

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 25, 2013, 10:25
Default transient convergence criteria
  #1
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Hi,
I'm working on a periodic simulation and I'd like to set up a temporal convergence criteria. It would be something like
if variable(t+T)=variable(t) then stop simulation

In the swak4foam library there are tools to stop a simulation if a criteria is reached, something like (in controlDict) :

Code:
    stopHighVel
    {
        type panicDump ;
        fieldName Q ;
        minimum -1;
        maximum 0.001;
        verbose true;
    }
My question is,how to access the data on a specified patch at a specified time ?

Regards,

Florian
Hiroshiman is offline   Reply With Quote

Old   June 25, 2013, 14:42
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
Hi,
I'm working on a periodic simulation and I'd like to set up a temporal convergence criteria. It would be something like
if variable(t+T)=variable(t) then stop simulation

In the swak4foam library there are tools to stop a simulation if a criteria is reached, something like (in controlDict) :

Code:
    stopHighVel
    {
        type panicDump ;
        fieldName Q ;
        minimum -1;
        maximum 0.001;
        verbose true;
    }
My question is,how to access the data on a specified patch at a specified time ?

Regards,

Florian
Abusing that functionObject would be hardcore. But have a look at writeAndEndSwakExpression in the simpleSwakFunctionObjects-library. That might be EXACTLY what you're looking for (stops the run if a logical expression evaluates to "true" - either everywhere ("and") or somewhere ("or"))
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   June 25, 2013, 15:28
Default
  #3
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Thank you for writeAndEndSwakExpression, I didn't know this one. I'm still wondering how to access data at a specified time. oldTime only works for one timeStep in the past...
Any idea ?

Regards,

Florian
Hiroshiman is offline   Reply With Quote

Old   June 25, 2013, 16:00
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
Thank you for writeAndEndSwakExpression, I didn't know this one. I'm still wondering how to access data at a specified time. oldTime only works for one timeStep in the past...
Any idea ?

Regards,

Florian
Yep. Delayed variable
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   June 28, 2013, 12:14
Default
  #5
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Thank you very much, a mix of delayedVariables and writeAndEndSwakExpression works perfectly !
Regards,
Florian.
Hiroshiman is offline   Reply With Quote

Old   June 28, 2013, 14:16
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
Thank you very much, a mix of delayedVariables and writeAndEndSwakExpression works perfectly !
Thank YOU. Without you I wouldn't have thought that delayed variables can be used for convergence-checking
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   June 29, 2013, 08:14
Default
  #7
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
Thank you very much, a mix of delayedVariables and writeAndEndSwakExpression works perfectly !
Regards,
Florian.
Can you post the code? Might be useful for people in the future.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   June 29, 2013, 09:13
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by akidess View Post
Can you post the code? Might be useful for people in the future.
Even better: Adding it under http://openfoamwiki.net/index.php/Co...Usage_examples would make sure that people don't have to search threads for it
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 2, 2013, 11:41
Default
  #9
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Even better: Adding it under http://openfoamwiki.net/index.php/Co...Usage_examples would make sure that people don't have to search threads for it
I guess I can compete for the ugliest way of doing things but it does work (so far).
Test case : one intlet with a sinusoidal pressure, 2 free outlets.

Code:
    stopIfCrit {
            type writeAndEndSwakExpression;
            valueType internalField;
            logicalExpression "(maxU1 < threshold) && (maxU2 < threshold) && (tt >= 1.5) && (test > 0.5) ";
            /* In this case 2 outlets are considered and tested. The (very basic) criteria used is the maximum velocity at the outlet patches. The flow is periodic and supposed physically converged if the criteria values are the same at t and t+T.
            The two first tests are the velocities comparison.
            The third one is a delay because of the unphysical behaviour that can appear at the beginning of the simulation.
            The fourth is used to keep the simulation running for one period after the convergence is reached.*/
            logicalAccumulation and;
            variables (
                "UA1fter{patch'outlet1}=max(mag(U));" //delayed criteria on outlet1
                "Ub41{patch'outlet1}=max(mag(U));" // criteria on outlet1
                "UA2fter{patch'outlet2}=max(mag(U));"
                "Ub42{patch'outlet2}=max(mag(U));"
                "maxU1=100*mag(UA1fter-Ub41)/mag(UA1fter);"
                "maxU2=100*mag(UA2fter-Ub42)/mag(UA2fter);"
                "threshold=5;" // 5% of difference accepted
                "tt=time();"
                "test=((maxU1 < threshold) && (maxU2 < threshold) && (tt >= 1.5))?   1  : 0;" // test done with a delay of T.
            );
            delayedVariables (
                {
                    name UA1fter;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "100";
                }
                {
                    name UA2fter;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "100";
                }
                {
                    name test;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "0";
                }               
                );
            verbose true;
            outputControlMode timestep;
            outputInterval 1;
                }
What it looks like :

With : blue = p(inlet), pink = 5% threshold, red and green : convergence criteria on both outlets.

I was wondering : how can I add the period as a parameter ?


Florian

Last edited by Hiroshiman; July 2, 2013 at 15:31.
Hiroshiman is offline   Reply With Quote

Old   July 2, 2013, 16:20
Default
  #10
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
I guess I can compete for the ugliest way of doing things but it does work (so far).
Test case : one intlet with a sinusoidal pressure, 2 free outlets.

Code:
    stopIfCrit {
            type writeAndEndSwakExpression;
            valueType internalField;
            logicalExpression "(maxU1 < threshold) && (maxU2 < threshold) && (tt >= 1.5) && (test > 0.5) ";
            /* In this case 2 outlets are considered and tested. The (very basic) criteria used is the maximum velocity at the outlet patches. The flow is periodic and supposed physically converged if the criteria values are the same at t and t+T.
            The two first tests are the velocities comparison.
            The third one is a delay because of the unphysical behaviour that can appear at the beginning of the simulation.
            The fourth is used to keep the simulation running for one period after the convergence is reached.*/
            logicalAccumulation and;
            variables (
                "UA1fter{patch'outlet1}=max(mag(U));" //delayed criteria on outlet1
                "Ub41{patch'outlet1}=max(mag(U));" // criteria on outlet1
                "UA2fter{patch'outlet2}=max(mag(U));"
                "Ub42{patch'outlet2}=max(mag(U));"
                "maxU1=100*mag(UA1fter-Ub41)/mag(UA1fter);"
                "maxU2=100*mag(UA2fter-Ub42)/mag(UA2fter);"
                "threshold=5;" // 5% of difference accepted
                "tt=time();"
                "test=((maxU1 < threshold) && (maxU2 < threshold) && (tt >= 1.5))?   1  : 0;" // test done with a delay of T.
            );
            delayedVariables (
                {
                    name UA1fter;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "100";
                }
                {
                    name UA2fter;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "100";
                }
                {
                    name test;
                    delay 0.7;
                    storeInterval 0.001;
                    startupValue "0";
                }               
                );
            verbose true;
            outputControlMode timestep;
            outputInterval 1;
                }
Nice. Just one problem: you're testing for the maximum. So if on outlet1 the same maximum is on a different location it still might be judged as "converged". One possibility would be to use as valueType patch on outlet1 and instead of max(mag(U)) use mag(U). instead wrap the max around the expression maxU1. That way you'd get convergence if the values on the outlet are really the same. But this only works for one patch at once (to treat the outlet2 similarly AT THE SAME TIME) is a little bit more tricky

Quote:
Originally Posted by Hiroshiman View Post
What it looks like :

With : blue = p(inlet), pink = 5% threshold, red and green : convergence criteria on both outlets.

I was wondering : how can I add the period as a parameter ?
With "period" you mean the delay of the delayedVariables? This value can currently only be a fixed value. But if you want to set the values consistently then you can set a dictionary entry
Code:
defaultDelay 0.7;
and make all delays use that
Code:
delay $defaultDelay;
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 4, 2013, 12:21
Default
  #11
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Nice. Just one problem: you're testing for the maximum. So if on outlet1 the same maximum is on a different location it still might be judged as "converged". One possibility would be to use as valueType patch on outlet1 and instead of max(mag(U)) use mag(U). instead wrap the max around the expression maxU1. That way you'd get convergence if the values on the outlet are really the same. But this only works for one patch at once (to treat the outlet2 similarly AT THE SAME TIME) is a little bit more tricky
Hi ! I'm aware of this this limitation and wand to create 2 functions like this, for each outlets :
Code:
    convcrit1
    {
        type swakExpression;
        valueType patch;
        patchName outlet1;
        variables (
            //"dummy=p-mag(U);"
            "UA1fter{patch'outlet1}=mag(U);"
            "Ub41{patch'outlet1}=mag(U);"
        );
        delayedVariables (
        {
            name UA1fter;
            delay 0.7;
            storeInterval 0.001;
            startupValue "100";
        });
        accumulations (
            max
        );
        expression "100*mag(UA1fter-Ub41)/mag(UA1fter)";
        verbose true;
        autoInterpolate true;
        warnAutoInterpolate false;
        outputControlMode timestep;
        outputInterval 1;
}
and then get the results to be evaluated in the function writeAndEndSwakExpression but I still have problems to exchange data from a function to another.

Quote:
Originally Posted by gschaider View Post
With "period" you mean the delay of the delayedVariables? This value can currently only be a fixed value. But if you want to set the values consistently then you can set a dictionary entry
Code:
defaultDelay 0.7;
and make all delays use that
Code:
delay $defaultDelay;
Thank you !

Florian
Hiroshiman is offline   Reply With Quote

Old   July 8, 2013, 15:59
Default
  #12
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Hiroshiman View Post
Hi ! I'm aware of this this limitation and wand to create 2 functions like this, for each outlets :
Code:
    convcrit1
    {
        type swakExpression;
        valueType patch;
        patchName outlet1;
        variables (
            //"dummy=p-mag(U);"
            "UA1fter{patch'outlet1}=mag(U);"
            "Ub41{patch'outlet1}=mag(U);"
        );
        delayedVariables (
        {
            name UA1fter;
            delay 0.7;
            storeInterval 0.001;
            startupValue "100";
        });
        accumulations (
            max
        );
        expression "100*mag(UA1fter-Ub41)/mag(UA1fter)";
        verbose true;
        autoInterpolate true;
        warnAutoInterpolate false;
        outputControlMode timestep;
        outputInterval 1;
}
and then get the results to be evaluated in the function writeAndEndSwakExpression but I still have problems to exchange data from a function to another.
If you're on outlet1 you don't have to write UA1fter{patch'outlet1}. UA1fter is sufficient.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   April 8, 2015, 13:34
Smile
  #13
Member
 
Liam
Join Date: Aug 2013
Posts: 40
Rep Power: 13
Many is on a distinguished road
Hi everyone,

I am not understanding well the use of this wonderful tool.

I would like to stop my (steady) simulation when Residuals are below a given threshold (let's say 1e-4) and outlet velocity remains unchanged with iterations, so, I have included this in my controDict file:
velocity_outlet
{
type patchExpression;
accumulations (
average
);
patches (
out
);
expression "mag(U)";
verbose true;
outputControl timeStep;
outputInterval 1;
}

This computes averaged outlet velocity as I desired.

But now I am not sure how to compare old and present values. I would like to:

if
|uaveraged(iteration n)-uaveraged(iteration n-1)|<0.1
and
Residuals<1e-4
then
STOP

Based on the code I have seen here, I have tried something like this( forget about the Residuals in this first try)


stopIfCrit {
type writeAndEndSwakExpression;
valueType internalField;
logicalExpression "(tol < threshold)";

logicalAccumulation and;
variables (
"UA1fter=velocity_outlet;" //delayed criteria on outlet1
"Ub41=velocity_outlet;"

"tol=mag(UA1fter-Ub41);"

"threshold=0.5;"

"test=((tol < threshold) )? 1 : 0;"
);
delayedVariables (
{
name UA1fter;
delay 1;
storeInterval 1;
startupValue "1";
}

{
name test;
delay 1;
storeInterval 1;
startupValue "0";
}
);
verbose true;
outputControlMode timestep;
outputInterval 1;
}

But nothing happens. It seems that I am not telling OpenFOAM when it has to stop .This definition I have tried looks so weird:

"UA1fter=velocity_outlet;" //delayed criteria on outlet1
"Ub41=velocity_outlet;"

Does anybody know how I have to proceed to compare a computed value in the previous iteration with this value in the current iteration?


Thanks in advance!
Many is offline   Reply With Quote

Old   April 8, 2015, 14:03
Default
  #14
Member
 
Join Date: Sep 2012
Posts: 51
Rep Power: 14
Hiroshiman is on a distinguished road
Quote:
Originally Posted by Many View Post
Hi everyone,

I am not understanding well the use of this wonderful tool.

I would like to stop my (steady) simulation when Residuals are below a given threshold (let's say 1e-4) and outlet velocity remains unchanged with iterations, so, I have included this in my controDict file:
velocity_outlet
{
type patchExpression;
accumulations (
average
);
patches (
out
);
expression "mag(U)";
verbose true;
outputControl timeStep;
outputInterval 1;
}

This computes averaged outlet velocity as I desired.

But now I am not sure how to compare old and present values. I would like to:

if
|uaveraged(iteration n)-uaveraged(iteration n-1)|<0.1
and
Residuals<1e-4
then
STOP

Based on the code I have seen here, I have tried something like this( forget about the Residuals in this first try)


stopIfCrit {
type writeAndEndSwakExpression;
valueType internalField;
logicalExpression "(tol < threshold)";

logicalAccumulation and;
variables (
"UA1fter=velocity_outlet;" //delayed criteria on outlet1
"Ub41=velocity_outlet;"

"tol=mag(UA1fter-Ub41);"

"threshold=0.5;"

"test=((tol < threshold) )? 1 : 0;"
);
delayedVariables (
{
name UA1fter;
delay 1;
storeInterval 1;
startupValue "1";
}

{
name test;
delay 1;
storeInterval 1;
startupValue "0";
}
);
verbose true;
outputControlMode timestep;
outputInterval 1;
}

But nothing happens. It seems that I am not telling OpenFOAM when it has to stop .This definition I have tried looks so weird:

"UA1fter=velocity_outlet;" //delayed criteria on outlet1
"Ub41=velocity_outlet;"

Does anybody know how I have to proceed to compare a computed value in the previous iteration with this value in the current iteration?


Thanks in advance!

Hi,
you can look at the variables values that are stored during the simulation to check if they are what you expect (in the swak4Foam folder at each timeStep).
You can use the [CODE ] [/CODE ] bracket to make the code readable.
Hiroshiman is offline   Reply With Quote

Old   April 8, 2015, 14:45
Default
  #15
Member
 
Liam
Join Date: Aug 2013
Posts: 40
Rep Power: 13
Many is on a distinguished road
Hi Hiroshiman,

The values of:

velocity_outlet
{
type patchExpression;
accumulations (
average
);
patches (
out
);
expression "mag(U)";
verbose true;
outputControl timeStep;
outputInterval 1;
}

are written in postProcessing folder (no swak4foam folder in my case)

The problem is I don't know how to use this values to stop my simulation when differences between consecutive iterations is small.

Some more help will be much aprecciated.
Many 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
transient convergence mohsen.samie CFX 8 September 15, 2015 11:18
What is the criteria for convergence in transient problems? abcd ANSYS 0 July 26, 2015 13:03
SIMPLE algorithm, convergence criteria bbasal Main CFD Forum 3 December 3, 2011 00:24
What value shall I set for the Convergence criteria? steventay CFX 7 May 14, 2010 13:44
Convergence Criteria edwin FLUENT 1 February 14, 2008 20:24


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