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

Dynamic under-relaxation

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

Reply
 
LinkBack Thread Tools Display Modes
Old   February 19, 2010, 17:55
Default Dynamic under-relaxation
  #1
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 10
benk is on a distinguished road
Just out of curiosity, has anybody tried to implement (or perhaps it exists and I just don't know about it) a type of "dynamic under/over-relaxation" function where the relaxation parameter changes on the fly based on the residual history?

I've done this before in my own simple matlab code and I've found that it can help speed up convergence or simply get a simulation to converge, especially for highly coupled systems.
benk is offline   Reply With Quote

Old   February 25, 2010, 02:17
Default
  #2
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,894
Rep Power: 26
alberto will become famous soon enoughalberto will become famous soon enough
Quote:
Originally Posted by benk View Post
Just out of curiosity, has anybody tried to implement (or perhaps it exists and I just don't know about it) a type of "dynamic under/over-relaxation" function where the relaxation parameter changes on the fly based on the residual history?

I've done this before in my own simple matlab code and I've found that it can help speed up convergence or simply get a simulation to converge, especially for highly coupled systems.
Hi,

you can quite easily change the relaxation factor in OpenFOAM, also dynamically. You simply need to specify the value when you call relax(). For example

UEqn.relax(0.7);

Of course in your case the fixed value is replaced by a variable.

In addition, you can access the residuals defining a solverPerformance object

solverPerformance sp;

then, when you solve

sp = solve(....);

or

sp = UEqn.solve();

and, to recover the initial residual (a scalar called resU in my example)

resU = sp.initialResidual();

Best,
__________________
Alberto Passalacqua

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
OpenQBMM - An open-source implementation of quadrature-based moment methods
alberto is offline   Reply With Quote

Old   February 25, 2010, 11:44
Default
  #3
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 10
benk is on a distinguished road
Aha! Thanks. That sounds like exactly what I need.

What's the best way to find these sorts of things out? Do I have to dig through the code or is there a better way?
benk is offline   Reply With Quote

Old   February 25, 2010, 12:53
Default
  #4
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,894
Rep Power: 26
alberto will become famous soon enoughalberto will become famous soon enough
Quote:
Originally Posted by benk View Post
Aha! Thanks. That sounds like exactly what I need.

What's the best way to find these sorts of things out? Do I have to dig through the code or is there a better way?
Unfortunately the code is the only actually complete reference. You find how residuals can be extracted in simpleFoam, and the relaxation with specified URF in the code can be seen applied in pimpleFoam.

Sooner or later I'll add these info to the wiki as part of my plan to provide a bit more info, but if you can do that, I can review the page (yes, I'm shamelessly asking for wiki volunteers to help )

Best,
__________________
Alberto Passalacqua

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
OpenQBMM - An open-source implementation of quadrature-based moment methods
alberto is offline   Reply With Quote

Old   March 1, 2010, 12:21
Default
  #5
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 10
benk is on a distinguished road
There's another piece that I can't figure out:

How can I return the current value of the relaxation factor?

Or better yet, set it using code like:
C_Eqn.relaxationFactor() = C_Eqn.relaxationFactor() / 5;

I've tried: C_Eqn.relaxationFactor(), C_Eqn.relax().value(), none seem to work...

For example, this is the code that I'm trying to implement in my solver which keeps track of the last 10 residual values and if the residual value is increasing, then I want to divide the relaxation factor by 5:

Code:
double residual[10];
int res_index = count % 10; // count is just the number of iterations

lduMatrix::solverPerformance C_res;
fvScalarMatrix C_Eqn
(
  fvm::laplacian(Dc, C)
);
C_Eqn.relax(); 
C_res = solve(C_Eqn);

residual[res_index] = C_res.initialResidual(); // this all works and stores last 10 residual values

if (residual[9]-residual[0] > 10) {
  // This part doesn't work. I'd like to just reduce the relaxation factor by 5
  C_Eqn.relaxationFactor() = C_Eqn.relaxationFactor() / 5;
}
benk is offline   Reply With Quote

Old   June 8, 2010, 03:59
Default
  #6
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
What happens when you try that line? It might be due to integer division, use " / 5.0" instead.
akidess is offline   Reply With Quote

Old   June 8, 2010, 09:17
Default
  #7
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 10
benk is on a distinguished road
I found that it's easier just to define a variable as my relaxation factor and then relax with that variable. Something like this:

Code:
scalar dampingCoeff = 0.5;

<insert algorithm to change dampingCoeff based on convergence>

CEqn.relax(dampingCoeff);
benk 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
Regarding Negative volume detected in Dynamic mesh Vinay Morabad FLUENT 9 April 10, 2015 23:00
Dynamic Mesh Problem. Tom Clark FLUENT 9 July 7, 2010 07:56
Relaxation and convergence sammi Phoenics 0 March 20, 2008 04:32
Dynamic mesh + grid adapt = Crash! (Files included BillH FLUENT 4 July 24, 2007 15:31
Question on adjusting relaxation factor CFD Rookie Main CFD Forum 3 January 26, 2004 15:37


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