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

Monitor user-defined quantity along with residuals in log file

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 3, 2020, 17:36
Default Monitor user-defined quantity along with residuals in log file
  #1
New Member
 
Suraj Pawar
Join Date: Sep 2013
Posts: 9
Rep Power: 8
sap_92 is on a distinguished road
I am running a simple CFD simulation of flow in a backward-facing channel. I would like to monitor the average value of the square of velocity over the whole domain (sum of the square of velocity at all grid points/ number of grid points) as the solution progresses. I would like to write this quantity in a log file along with residual information. If it is not easy to write along with residual information, is there any other way that I can write the user-defined quantity at every time step in a separate log file. Basically, I would like to use the history of this quantity to alter some of the simulation parameters while the simulation is running.

Thank you for your help.
sap_92 is offline   Reply With Quote

Old   July 7, 2020, 07:10
Default
  #2
Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 84
Rep Power: 5
crubio.abujas is on a distinguished road
Hello Suraj!

One possibility is to create your own functionObject to do so. I don't know exactly what residuals are you interested on, but as a concept trial I've implemented a functionObject that returns the average square U of the entire domain along with the residual of U in each direction and write them into postProcessing/0/squareU. Right now the residuals are hardcoded, so if you need another field you must change it in the code.

I let you a link to the source code here
You just have to position yourself in the folder and execute wmake. Once compile just add the following code to controlDict functions dictionary.

Code:
    squareU
    {
        type           squareU;
        libs           ("libsquareUFunctionObject.so");
        writeControl   timeStep;
        writeInterval  1;
    }
Other option could be add a codedFixed function object to print the UČ field and then process it with pyFoam. But that may require to manage multiple files, and so.

Concerning the changes in the controlDict, I think there shall be possible to code some rules to automatically change them, but probably you want to control it yourself by hand. Nevertheless if you think you get a strategy to work with you can check how to code it.

Let me know if it works!
crubio.abujas is offline   Reply With Quote

Old   July 7, 2020, 09:17
Default
  #3
RGS
New Member
 
Rohit George Sebastian
Join Date: May 2017
Posts: 17
Rep Power: 5
RGS is on a distinguished road
Quote:
Originally Posted by sap_92 View Post
I am running a simple CFD simulation of flow in a backward-facing channel. I would like to monitor the average value of the square of velocity over the whole domain (sum of the square of velocity at all grid points/ number of grid points) as the solution progresses. I would like to write this quantity in a log file along with residual information. If it is not easy to write along with residual information, is there any other way that I can write the user-defined quantity at every time step in a separate log file. Basically, I would like to use the history of this quantity to alter some of the simulation parameters while the simulation is running.

Thank you for your help.

Hello Suraj,


I think it is possible to get a log file of the residuals using swak4foam - at least the residuals that are reported by the solver and appear in the terminal. I hope this helps.
RGS is offline   Reply With Quote

Old   July 7, 2020, 19:38
Default
  #4
New Member
 
Suraj Pawar
Join Date: Sep 2013
Posts: 9
Rep Power: 8
sap_92 is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
Hello Suraj!

One possibility is to create your own functionObject to do so. I don't know exactly what residuals are you interested on, but as a concept trial I've implemented a functionObject that returns the average square U of the entire domain along with the residual of U in each direction and write them into postProcessing/0/squareU. Right now the residuals are hardcoded, so if you need another field you must change it in the code.

I let you a link to the source code here
You just have to position yourself in the folder and execute wmake. Once compile just add the following code to controlDict functions dictionary.

Code:
    squareU
    {
        type           squareU;
        libs           ("libsquareUFunctionObject.so");
        writeControl   timeStep;
        writeInterval  1;
    }
Other option could be add a codedFixed function object to print the UČ field and then process it with pyFoam. But that may require to manage multiple files, and so.

Concerning the changes in the controlDict, I think there shall be possible to code some rules to automatically change them, but probably you want to control it yourself by hand. Nevertheless if you think you get a strategy to work with you can check how to code it.

Let me know if it works!
When I executed the wmake command in the folder, I got an error that Residuals.H file is not in the directory. I think you forgot to attach the Residual.H file in the source code . Can you please attach it to the source code? Thank you very much for your help.
sap_92 is offline   Reply With Quote

Old   July 10, 2020, 02:57
Default
  #5
Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 84
Rep Power: 5
crubio.abujas is on a distinguished road
Residual.H should be defined within the finiteVolume dependencies (inside Make/options). At least that it the case for OF6. Which version of OF are you using? Maybe other versions have different management of this dependency.
crubio.abujas is offline   Reply With Quote

Old   July 10, 2020, 12:10
Default
  #6
New Member
 
Suraj Pawar
Join Date: Sep 2013
Posts: 9
Rep Power: 8
sap_92 is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
Residual.H should be defined within the finiteVolume dependencies (inside Make/options). At least that it the case for OF6. Which version of OF are you using? Maybe other versions have different management of this dependency.
I am using OF5. I downloaded the file, extracted it, and then entered into the extracted folder. Then, I just typed wmake in the terminal. Am I a missing something? There is a residuals.H file in the OpenFOAM-5.x/src/functionObjects/utilities in my installation directory.
Thank you.
sap_92 is offline   Reply With Quote

Old   July 10, 2020, 13:49
Default
  #7
Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 84
Rep Power: 5
crubio.abujas is on a distinguished road
It seems that on OF7 they added a new Residual class (note the capitalization) to ease the manage of those, but OF5 is lacking for it. You've done it right, it just that the code was not adapted for your specific version.

I've tested this new version in OF5 and worked for me. The steps to compile it are the same. Let me know if you find further problems!
crubio.abujas is offline   Reply With Quote

Old   July 10, 2020, 17:55
Default
  #8
New Member
 
Suraj Pawar
Join Date: Sep 2013
Posts: 9
Rep Power: 8
sap_92 is on a distinguished road
Quote:
Originally Posted by crubio.abujas View Post
It seems that on OF7 they added a new Residual class (note the capitalization) to ease the manage of those, but OF5 is lacking for it. You've done it right, it just that the code was not adapted for your specific version.

I've tested this new version in OF5 and worked for me. The steps to compile it are the same. Let me know if you find further problems!
Thank you very much. It worked. This is exactly what I was looking for. Can you please point me the place where I can make changes so that residuals for all equations will be written in a squareU.dat file. For example, I would like to know the history of all residuals which appears in a log file when you run the simulation (simpleFoam > log).

Thank you very much for your help.
sap_92 is offline   Reply With Quote

Old   July 13, 2020, 16:08
Default
  #9
Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 84
Rep Power: 5
crubio.abujas is on a distinguished road
To change the code just modify the write() function inside squareU.C, You need to know the type of data (U-> vector, p->scalar).

Code:
bool Foam::functionObjects::squareU::write()
{
    logFiles::write();

    writeTime(file());
    writeSquareU();        
    writeResidual<vector>("U");


    // Added pressure residuals

    writeResidual<scalar>("p");

    file() << endl;
    return true;
}

In order to remember it is a good idea to change the header as well. Inside the same file change writeFileHeader()


Code:
void Foam::functionObjects::squareU::writeFileHeader(const label i)
{
    if (Pstream::master())
    {
        writeHeader(file(), "squareU");
        writeCommented(file(), "Time\tsquareU");
        writeFileHeader<vector>("U");
        writeFileHeader<scalar>("p");
    }

    file() << endl;
}

Once change, recompile and run!
crubio.abujas is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 28 August 6, 2020 11:58
[Other] Tabulated thermophysicalProperties library chriss85 OpenFOAM Community Contributions 60 April 23, 2020 10:53
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 09:07
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 11 November 1, 2016 06:43
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 21:53


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