CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Dynamic under-relaxation (https://www.cfd-online.com/Forums/openfoam-programming-development/72859-dynamic-under-relaxation.html)

benk February 19, 2010 16:55

Dynamic under-relaxation
 
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.

alberto February 25, 2010 01:17

Quote:

Originally Posted by benk (Post 246649)
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,

benk February 25, 2010 10:44

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?

alberto February 25, 2010 11:53

Quote:

Originally Posted by benk (Post 247439)
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 :D)

Best,

benk March 1, 2010 11:21

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


akidess June 8, 2010 03:59

What happens when you try that line? It might be due to integer division, use " / 5.0" instead.

benk June 8, 2010 09:17

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


allett02015 August 12, 2015 13:48

Hello to everybody. Does anybody know wy when I use a segregated approuch for the velocity solve ( ...) gives back a non empty opject of the type solverPerformance but when I solve it coupled solve (...) gives me back the standard constructor containing zeros for ntierations, initalResidual, finialResidual and so one.


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