CFD Online URL
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

swak4foam : transient convergence criteria

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

Reply
 
LinkBack Thread Tools Display Modes
Old   June 25, 2013, 10:25
Default swak4foam : transient convergence criteria
  #1
Member
 
Join Date: Sep 2012
Posts: 43
Rep Power: 4
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: 3,889
Rep Power: 38
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: 43
Rep Power: 4
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: 3,889
Rep Power: 38
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: 43
Rep Power: 4
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: 3,889
Rep Power: 38
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: Delft, Netherlands
Posts: 918
Rep Power: 16
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.
*Check out the scientific computing exchange http://scicomp.stackexchange.com
akidess is offline   Reply With Quote

Old   June 29, 2013, 09:13
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
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: 43
Rep Power: 4
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: 3,889
Rep Power: 38
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: 43
Rep Power: 4
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: 3,889
Rep Power: 38
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

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check the convergence of the transient run--> HOW ??!! mohammad CFX 4 February 13, 2012 06:17
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 swarley FLUENT 3 June 24, 2009 12:18
Convergence Criteria edwin FLUENT 1 February 14, 2008 20:24


All times are GMT -4. The time now is 02:41.