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

Change solver tolerance depending on solution

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 30, 2021, 23:34
Default Change solver tolerance depending on solution
  #1
Member
 
Martin
Join Date: Dec 2011
Posts: 40
Rep Power: 14
msaravia is on a distinguished road
Hello everyone.

I need to change the solver tolerances while running. More specifically, I need to change the absolute tolerance of the solver after a certain number of iterations.

I know the fvMatrix class has a solver object; but neither of them has a getter implemented to return a reference to the tolerance parameter (which is read from fvSolution).

Do you have any idea about how I can achieve this? Thanks in advance.
msaravia is offline   Reply With Quote

Old   May 31, 2021, 01:51
Default
  #2
Member
 
Join Date: Jun 2011
Location: Germany
Posts: 59
Rep Power: 14
Siassei is on a distinguished road
A little hint.
Not tested until yet, but adding runTimeModifiable to fvSolution?

doc:
runTimeModifiable
Switch for whether dictionaries, e.g. controlDict, are re-read during a simulation at the beginning of each time step, allowing the user to modify parameters during a simulation.
Siassei is offline   Reply With Quote

Old   May 31, 2021, 10:08
Default
  #3
Member
 
Martin
Join Date: Dec 2011
Posts: 40
Rep Power: 14
msaravia is on a distinguished road
Quote:
Originally Posted by Siassei View Post
A little hint.
Not tested until yet, but adding runTimeModifiable to fvSolution?

doc:
runTimeModifiable
Switch for whether dictionaries, e.g. controlDict, are re-read during a simulation at the beginning of each time step, allowing the user to modify parameters during a simulation.
Hi Thomas, thank for the hint! I have considered it, specially because if I get to access the fvSolution object I would need to make sure that this option is activated in order to get the dictionary to be read at every iteation.

Apparently I can access the linear solver controls through the mesh as mesh.solverDict(fieldName). fvMesh is derived from fvSolution so that all fields have access to the fvSolution from the mesh reference they hold.

I will keep you posted
msaravia is offline   Reply With Quote

Old   June 1, 2021, 11:55
Default
  #4
Member
 
Martin
Join Date: Dec 2011
Posts: 40
Rep Power: 14
msaravia is on a distinguished road
Well, after trying several things. I managed to change the solver settings at runtime without needing to write the dictionary to file.
For anyone needing to do it, here it is my solution.

a) Create a dictionary reading the original solver settings.

Code:
IOdictionary solDict
(
	IOobject
	(
	"fvSolution",
	runTime.caseSystem(),
	runTime,
	IOobject::MUST_READ,
	IOobject::AUTO_WRITE
	)
);

dictionary& solverControl = solDict.subDict("solvers").subDict("A");
b) modify the solver control as needed

Code:
solverControl.set("tolerance", 1E-10);
C) Now, the magic. Just call the solver with the control dictionary as argument.

Code:
AEqn.solve(solverControl);
The solution was so simple that now I feel the dumbest person in the world. You can make fun of me; I take it.

However, I still need to change the number of non-orthogonal correctors on the fly, which apparently has not a simple solution.
msaravia 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
Foam::error::printStack(Foam::Ostream&) with simpleFoam -parallel U.Golling OpenFOAM Running, Solving & CFD 52 September 23, 2023 03:35
icoFoam Courant number growth problem tdof OpenFOAM Running, Solving & CFD 12 May 24, 2023 14:00
[ANSYS Meshing] Help with element size sandri_92 ANSYS Meshing & Geometry 14 November 14, 2018 07:54
alpha value negative silviliril OpenFOAM Programming & Development 1 June 1, 2018 14:57
2D isothermal cylinder not converging UPengineer OpenFOAM Running, Solving & CFD 7 March 13, 2014 05:17


All times are GMT -4. The time now is 08:33.