|
[Sponsors] |
Monitor user-defined quantity along with residuals in log file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 3, 2020, 18:36 |
Monitor user-defined quantity along with residuals in log file
|
#1 |
New Member
Suraj Pawar
Join Date: Sep 2013
Posts: 10
Rep Power: 13 |
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. |
|
July 7, 2020, 08:10 |
|
#2 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9 |
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; } 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! |
|
July 7, 2020, 10:17 |
|
#3 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 42
Rep Power: 9 |
Quote:
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. |
||
July 7, 2020, 20:38 |
|
#4 | |
New Member
Suraj Pawar
Join Date: Sep 2013
Posts: 10
Rep Power: 13 |
Quote:
|
||
July 10, 2020, 03:57 |
|
#5 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9 |
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.
|
|
July 10, 2020, 13:10 |
|
#6 | |
New Member
Suraj Pawar
Join Date: Sep 2013
Posts: 10
Rep Power: 13 |
Quote:
Thank you. |
||
July 10, 2020, 14:49 |
|
#7 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9 |
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! |
|
July 10, 2020, 18:55 |
|
#8 | |
New Member
Suraj Pawar
Join Date: Sep 2013
Posts: 10
Rep Power: 13 |
Quote:
Thank you very much for your help. |
||
July 13, 2020, 17:08 |
|
#9 |
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9 |
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! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using PengRobinsonGas EoS with sprayFoam | Jabo | OpenFOAM Running, Solving & CFD | 36 | July 16, 2024 04:52 |
[Other] Tabulated thermophysicalProperties library | chriss85 | OpenFOAM Community Contributions | 62 | October 2, 2022 04:50 |
[swak4Foam] funkyDoCalc with OF2.3 massflow | NiFl | OpenFOAM Community Contributions | 14 | November 25, 2020 04:30 |
polynomial BC | srv537 | OpenFOAM Pre-Processing | 4 | December 3, 2016 10:07 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |