CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

adapting tolerance of matrix solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 29, 2015, 12:10
Default adapting tolerance of matrix solver
  #1
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
Hello,

the tolerance of the matrix solver is set in fVsolution. This is ok for me, but under certain circumstances, I want to adapt the value, or minIter that is specified.

Is there somebody who knows, how to do that? I know how to get solverperformance, but not how to change convergence criteria within the application solver code.

Regards,

Daniel
danny123 is offline   Reply With Quote

Old   May 4, 2015, 09:13
Default
  #2
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
I have made some progress, but I am still missing some information on the issue. The information is defined as a dictionary. I can get the information within the dictionary. I added the following code:

Code:
        const dictionary& solverControls_p = mesh.solver(p_rgh.select(pimple.finalInnerIter()));

         Info<< " before changing solverControls_p = "
            << solverControls_p
            << endl;
As an Output I get:

HTML Code:
 solverControls_p = 
{
    solver          PCG_norm;
    preconditioner  DIC;
    tolerance       1e-05;
    relTol          0.001;
    maxIter         20000;
which is what I have specified in fvSolutions. Now I want to let's say divide "tolerance" by 10 (not changing fvSolutions though). Is this possible? How do I overwrite the value of "tolerance" in solverControls_p?

Regards,

Daniel
danny123 is offline   Reply With Quote

Old   May 4, 2015, 10:25
Default
  #3
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

If you take a look at fvMesh::solver [1] documentation (which was in fact inherited from solution class), you can learn that it returns dictionary with solver settings. So the call

Code:
pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())));
Is a call to fvMatrix::sove(dictionary) [2]. And then you can look at dictionary class documentation, to learn about set method [3].

So, you either construct dictionary yourself, set desired value of tolerance (along with other linear solver parameters), and then pass this dictionary to solve method. Or you create a copy of fvMesh::solver, set desired value of the tolerance, and the pass the dictionary to solve method.

The second variant is more convenient as it takes other settings from fvSolution (you just overwrite tolerance entry of the dictionary), while using the first variant, you have to set all solver settings yourself.

1. http://foam.sourceforge.net/docs/cpp...f7779f1b8870e2
2. http://foam.sourceforge.net/docs/cpp...161fe7f7e6b9c8
3. http://foam.sourceforge.net/docs/cpp...5731ffe067b39f
alexeym is offline   Reply With Quote

Old   May 4, 2015, 11:34
Default
  #4
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
Hi Alexey,

Thanks again for your help. Your suggestion seems logical to me, however i do not get to work. If I use the set method (method 2), I guess I will get what I want. I tried:

Code:
solverControls_p.set(tolerance,1e-06);
the compiler says that tolerance is undefined. I looked at the definition, which is I guess:

Code:
void Foam::dictionary::set(entry* entryPtr)
I tried various combinations of that type, but this did not work either. Can you help?

Regards,

Daniel
danny123 is offline   Reply With Quote

Old   May 4, 2015, 13:19
Default
  #5
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

As you have used tolerance without quotes, compiler thinks it is a variable named tolerance. Do you have this variable? In general, you would use just a string "tolerance".

And you should use method [1] instead of [2]. The method is template, so you also supply type of the "tolerance" key (scalar). So the whole thing should be something like:

Code:
dictionary t(mesh.solver("field"));
t.set<scalar>("tolerance", 1e-20);
fieldEqn.solve(t);
1. http://foam.sourceforge.net/docs/cpp...2a284da0c05f4c
2. http://foam.sourceforge.net/docs/cpp...c8b1ac9e18460b
alexeym is offline   Reply With Quote

Old   May 5, 2015, 04:53
Default
  #6
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
Hi Alexey,

Thanks, this works perfectly.

Regards,

Daniel
danny123 is offline   Reply With Quote

Reply

Tags
tolerance change


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
solver tolerance in fvSolution fisch OpenFOAM Running, Solving & CFD 7 July 28, 2020 12:57
Getting iterations number of matrix solver danny123 OpenFOAM Programming & Development 4 March 3, 2015 09:00
IcoFoam stationary solution STRONGLY dependent on the tolerance of the linear solver Mehrez OpenFOAM Running, Solving & CFD 1 February 16, 2015 07:59
compressible two phase flow in CFX4.4 youngan CFX 0 July 2, 2003 00:32
solver for linear system with large sparse matrix Yangang Bao Main CFD Forum 1 October 25, 1999 05:22


All times are GMT -4. The time now is 16:06.