|
[Sponsors] |
Print percentage through run in stdout (in transient solvers) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 2, 2021, 06:21 |
Print percentage through run in stdout (in transient solvers)
|
#1 |
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 34
Rep Power: 6 |
Hi everyone,
I guess the title is self-explanatory. For that, one must query the following: 1. current time 2. calculate number of steps (based on the "endTime" and "deltaT") knowing these two we can do a simple calculation: Code:
percentage = current time / No. steps * 100 |
|
October 2, 2021, 17:16 |
|
#2 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 666
Rep Power: 14 |
Probably best to do this as a functionObject rather than editing the solver: drop the following into a file system/printFracRun:
Code:
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: dev \\/ M anipulation | ------------------------------------------------------------------------------- Description codedFunctionObject to calculate how far trhough a run the solver is and to print it out to the screen (as a %, with 1dp). To use, copy to system folder and add the following to the functions{} subdict of controlDict: #include "printFracRun" \*---------------------------------------------------------------------------*/ func1 { libs ( "libutilityFunctionObjects.so" ); type coded; name printFracRun; writeControl timeStep; writeInterval 1; codeWrite #{ scalar startTime = mesh().time().startTime().value(); scalar endTime = mesh().time().endTime().value(); scalar currentTime = mesh().time().value(); scalar pctComplete = int(10 * 100 * (currentTime - startTime) / (endTime - startTime))/10.0; //note: no check for div by zero! Info<< "[printFracRun]: simulation is " << pctComplete << "% complete." << endl; #}; } Code:
functions { #include "printFracRun" } |
|
October 3, 2021, 10:25 |
|
#3 |
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 34
Rep Power: 6 |
Your idea is even better. No need to calculate the number of time steps, and It works like a charm! Thanks a lot!
I think the division by zero only happens when the latestTime is set and its value is the same as the endTime, meaning it only happens when one mistakenly starts a finished run. So I guess no need to be worried about it. Is it possible to change the precision with something like “setprecision(x)” (I set the writePrecision to 18, and it prints so many decimal points)? I tested Foam::setprecision(3) and std::setprecision(3) and it didn't compile, simply because they are not a member of corresponding namespaces. |
|
October 3, 2021, 12:29 |
|
#4 | ||
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 666
Rep Power: 14 |
Glad that worked for you!
Quote:
Quote:
|
|||
October 3, 2021, 12:43 |
|
#5 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 666
Rep Power: 14 |
Okay - well, you learn something new every day! Yes - you can use the std c++ setprecision command. This seems to work:
Code:
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: dev \\/ M anipulation | ------------------------------------------------------------------------------- Description codedFunctionObject to calculate how far trhough a run the solver is and to print it out to the screen (as a %, with 1dp). To use, copy to system folder and add the following to the functions{} subdict of controlDict: #include "printFracRun" \*---------------------------------------------------------------------------*/ func1 { libs ( "libutilityFunctionObjects.so" ); type coded; name printFracRun; writeControl timeStep; writeInterval 1; codeInclude #{ #include "IOmanip.H" #}; codeWrite #{ scalar startTime = mesh().time().startTime().value(); scalar endTime = mesh().time().endTime().value(); scalar currentTime = mesh().time().value(); scalar pctComplete = 0; if (startTime == endTime) { pctComplete = 100.0; } else { pctComplete = 100 * (currentTime - startTime) / (endTime - startTime); } Info << setprecision(3); Info<< "[printFracRun]: simulation is " << pctComplete << "% complete." << endl; #}; } Last edited by Tobermory; October 4, 2021 at 03:40. |
|
October 3, 2021, 15:32 |
|
#6 |
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 34
Rep Power: 6 |
||
October 4, 2021, 03:44 |
|
#7 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 666
Rep Power: 14 |
Aaah, that was from a quick google search. The great thing about this forum is that it has been running for long enough that someone has probably had the same question as you at some stage!
Happy to help - this question caught my interest since I had wanted to do some functionObject coding last year using the simulation time, but couldn't work out how to do it at the time ... turns out it was easy all along! |
|
October 4, 2021, 09:11 |
|
#8 |
Member
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 34
Rep Power: 6 |
Yes, this forum is ancient
I believe it is possible to find them via Doxygen, not sure how to query, though. This is my first “functionObject” experience! I'm looking forward to using it for on-the-fly post-processing. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Question regarding transient solvers and steadyState | Shibi | OpenFOAM Running, Solving & CFD | 1 | May 14, 2021 11:24 |
Steady-State and Transient Solvers | 70m1 | OpenFOAM Running, Solving & CFD | 21 | May 8, 2021 07:09 |
Error Message during transient run on a cluster | balrog_f | CFX | 0 | June 17, 2017 03:18 |
Steady-State Transient solvers for miscible fluids | Filankes | OpenFOAM | 2 | January 29, 2014 17:47 |
convergence problem in using incompressible transient solvers. | Geon-Hong | OpenFOAM Running, Solving & CFD | 13 | November 24, 2011 05:48 |