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

Saving Residuals

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mykkujinu2201

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 1, 2021, 06:25
Default Saving Residuals
  #1
New Member
 
Raoul
Join Date: Apr 2021
Posts: 16
Rep Power: 5
rol97 is on a distinguished road
Hi everyone,
I am trying to save the residuals of the NS equations in a csv file to be able to easily post process those values.
Right now I am evaluating the residuals by substituting explicitly all the terms and evaluating the value of the equation
e.g.
Code:
residual = fvc::ddt(U)+fvc::div(phi, U)- fvc::laplacian(nu, U)+fvc::grad(p)
forAll(mesh.C(),I)
{
    res = residual[I]*residual[I];
} 
finalres = max(res.internalField()).value();
Is there a command line that I can use inside the solver that allows me to write the residual that is usually printed in the log, so that I don't have to manually re-evaluate it?

Thank you in advance.
rol97 is offline   Reply With Quote

Old   June 1, 2021, 06:30
Default You can save residuals using controlDict
  #2
Member
 
Jun
Join Date: Nov 2015
Posts: 57
Rep Power: 10
mykkujinu2201 is on a distinguished road
I thought controlDict can help you but it is not.

Sorry.

Add line below before while (runTime.run()) in your main code.
Code:
autoPtr<OFstream> residualPtr;
Add line below your calculation of residual.

Code:
  // Create the residual file if not already created
   if (residualPtr.empty())
     {
         // File update
         if (Pstream::master())
         {
             fileName residual;
	     word name_ = "residual";
	     
	     // Open new file at start up
	     residualPtr.reset(new OFstream("residual.dat"));
	 }
    }
   
   if (Pstream::master())
     {
       velFilePtr() << runTime.timeName() << tab << residual endl;
     }


Best,
Jun
rol97 likes this.
mykkujinu2201 is offline   Reply With Quote

Old   June 1, 2021, 07:05
Default
  #3
New Member
 
Raoul
Join Date: Apr 2021
Posts: 16
Rep Power: 5
rol97 is on a distinguished road
Thank you very much for your answer, I will try to understand the code and test it.
rol97 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
Saving the residuals in a dat file from TUI EmiS FLUENT 4 December 18, 2022 02:07
Cannot find functionObject file residuals vava10 OpenFOAM Pre-Processing 2 November 14, 2020 12:21
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch gschaider OpenFOAM Installation 225 August 25, 2015 19:43
motorBike Residuals for SST k-omega... and mine JR22 OpenFOAM Running, Solving & CFD 6 August 1, 2013 09:08
judging convergence through residuals MachZero Main CFD Forum 7 December 25, 2012 12:18


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