CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM CC Toolkits for Fluid-Structure Interaction (https://www.cfd-online.com/Forums/openfoam-cc-toolkits-fluid-structure-interaction/)
-   -   [stressAnalysis] Residual plot for OpenFOAM-ext problem. (https://www.cfd-online.com/Forums/openfoam-cc-toolkits-fluid-structure-interaction/117454-residual-plot-openfoam-ext-problem.html)

Sargam05 May 8, 2013 16:39

Residual plot for OpenFOAM-ext problem.
 
Hello everyone,

I am using OpenFOAM-ext for the stressAnalysis problem. I have successfully used Residual script to plot gnuplot in OpenFOAM1.7.1. I have made changes in the Residual script based on OpenFAOM-ext log file but it is showing some error.

Following is the log file in my case:

Time: 1

Time 1, Corrector 0, Solving for U using DICPCG, residual = 1, relative residual = 59362.4

Time 1, Solving for U, Initial residual = 1, Final residual = 1, Relative residual = 59362.4, No outer iterations 1
ExecutionTime = 26.44 s ClockTime = 27 s
ExecutionTime = 26.6 s


Time: 2

Time 2, Corrector 0, Solving for U using DICPCG, residual = 1, relative residual = 1

Time 2, Solving for U, Initial residual = 1, Final residual = 1, Relative residual = 1, No outer iterations 1
ExecutionTime = 37.93 s ClockTime = 38 s
ExecutionTime = 38.12 s


Time: 3

Time 3, Corrector 0, Solving for U using DICPCG, residual = 0.305633, relative residual = 1

Time 3, Solving for U, Initial residual = 0.305633, Final residual = 0.305633, Relative residual = 1, No outer iterations 1
ExecutionTime = 54.7 s ClockTime = 55 s
ExecutionTime = 54.9 s


Time: 4

Time 4, Corrector 0, Solving for U using DICPCG, residual = 0.229696, relative residual = 1

Time 4, Solving for U, Initial residual = 0.229696, Final residual = 0.229696, Relative residual = 1, No outer iterations 1
ExecutionTime = 66.4 s ClockTime = 67 s
ExecutionTime = 66.59 s


Time: 5

Time 5, Corrector 0, Solving for U using DICPCG, residual = 0.155004, relative residual = 1

Time 5, Solving for U, Initial residual = 0.155004, Final residual = 0.155004, Relative residual = 1, No outer iterations 1
ExecutionTime = 83.12 s ClockTime = 83 s
ExecutionTime = 83.3 s


Time: 6

Time 6, Corrector 0, Solving for U using DICPCG, residual = 0.088822, relative residual = 1

Time 6, Solving for U, Initial residual = 0.088822, Final residual = 0.088822, Relative residual = 1, No outer iterations 1
ExecutionTime = 96.02 s ClockTime = 96 s
ExecutionTime = 96.21 s


Time: 7

Time 7, Corrector 0, Solving for U using DICPCG, residual = 0.0763407, relative residual = 1

Time 7, Solving for U, Initial residual = 0.0763407, Final residual = 0.0763407, Relative residual = 1, No outer iterations 1
ExecutionTime = 109.27 s ClockTime = 110 s
ExecutionTime = 109.45 s


Time: 8

Time 8, Corrector 0, Solving for U using DICPCG, residual = 0.0426613, relative residual = 1

Time 8, Solving for U, Initial residual = 0.0426613, Final residual = 0.0426613, Relative residual = 1, No outer iterations 1
ExecutionTime = 121.37 s ClockTime = 122 s
ExecutionTime = 121.57 s


The script I am using to plot gnuplot is:

set terminal png
set output "filename.png"

set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Time'
cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
pause 1
reread


It is showing following error:

cat log | grep 'Solving for U' | cut -d' ' -f9
^
"Residuals", line 8: invalid command

sangeeta@sangeeta-laptop:~/Desktop/plateHole0.0001stress$ gnuplot Residuals

cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'Ux' with lines"
^
"Residuals", line 8: invalid command

sangeeta@sangeeta-laptop:~/Desktop/plateHole0.0001stress$ gnuplot Residuals

cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'Ux' with lines"
^
"Residuals", line 8: invalid command


Am I using wrong script? Can anyone explain how I can change the script to plot residual gnuplot based on log file (which I have mentioned above)?

Best regards,
Sangeeta

Tushar@cfd May 9, 2013 05:47

Quote:

Originally Posted by Sargam05 (Post 426190)
Hello everyone,

I am using OpenFOAM-ext for the stressAnalysis problem. I have successfully used Residual script to plot gnuplot in OpenFOAM1.7.1. I have made changes in the Residual script based on OpenFAOM-ext log file but it is showing some error.

Following is the log file in my case:

Time: 1

Time 1, Corrector 0, Solving for U using DICPCG, residual = 1, relative residual = 59362.4

Time 1, Solving for U, Initial residual = 1, Final residual = 1, Relative residual = 59362.4, No outer iterations 1
ExecutionTime = 26.44 s ClockTime = 27 s
ExecutionTime = 26.6 s


Time: 2

Time 2, Corrector 0, Solving for U using DICPCG, residual = 1, relative residual = 1

Time 2, Solving for U, Initial residual = 1, Final residual = 1, Relative residual = 1, No outer iterations 1
ExecutionTime = 37.93 s ClockTime = 38 s
ExecutionTime = 38.12 s


Time: 3

Time 3, Corrector 0, Solving for U using DICPCG, residual = 0.305633, relative residual = 1

Time 3, Solving for U, Initial residual = 0.305633, Final residual = 0.305633, Relative residual = 1, No outer iterations 1
ExecutionTime = 54.7 s ClockTime = 55 s
ExecutionTime = 54.9 s


Time: 4

Time 4, Corrector 0, Solving for U using DICPCG, residual = 0.229696, relative residual = 1

Time 4, Solving for U, Initial residual = 0.229696, Final residual = 0.229696, Relative residual = 1, No outer iterations 1
ExecutionTime = 66.4 s ClockTime = 67 s
ExecutionTime = 66.59 s


Time: 5

Time 5, Corrector 0, Solving for U using DICPCG, residual = 0.155004, relative residual = 1

Time 5, Solving for U, Initial residual = 0.155004, Final residual = 0.155004, Relative residual = 1, No outer iterations 1
ExecutionTime = 83.12 s ClockTime = 83 s
ExecutionTime = 83.3 s


Time: 6

Time 6, Corrector 0, Solving for U using DICPCG, residual = 0.088822, relative residual = 1

Time 6, Solving for U, Initial residual = 0.088822, Final residual = 0.088822, Relative residual = 1, No outer iterations 1
ExecutionTime = 96.02 s ClockTime = 96 s
ExecutionTime = 96.21 s


Time: 7

Time 7, Corrector 0, Solving for U using DICPCG, residual = 0.0763407, relative residual = 1

Time 7, Solving for U, Initial residual = 0.0763407, Final residual = 0.0763407, Relative residual = 1, No outer iterations 1
ExecutionTime = 109.27 s ClockTime = 110 s
ExecutionTime = 109.45 s


Time: 8

Time 8, Corrector 0, Solving for U using DICPCG, residual = 0.0426613, relative residual = 1

Time 8, Solving for U, Initial residual = 0.0426613, Final residual = 0.0426613, Relative residual = 1, No outer iterations 1
ExecutionTime = 121.37 s ClockTime = 122 s
ExecutionTime = 121.57 s


The script I am using to plot gnuplot is:

set terminal png
set output "filename.png"

set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Time'
cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
pause 1
reread


It is showing following error:

cat log | grep 'Solving for U' | cut -d' ' -f9
^
"Residuals", line 8: invalid command

sangeeta@sangeeta-laptop:~/Desktop/plateHole0.0001stress$ gnuplot Residuals

cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'Ux' with lines"
^
"Residuals", line 8: invalid command

sangeeta@sangeeta-laptop:~/Desktop/plateHole0.0001stress$ gnuplot Residuals

cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'Ux' with lines"
^
"Residuals", line 8: invalid command


Am I using wrong script? Can anyone explain how I can change the script to plot residual gnuplot based on log file (which I have mentioned above)?

Best regards,
Sangeeta

You missed to use the keywords: plot "< before your command.
plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines

:)

Tushar@cfd May 9, 2013 05:55

Also, refer the following page:

http://www.cfd-online.com/Forums/ope...residuals.html

Sargam05 May 9, 2013 15:53

Hi Tushar,

Thank so much for the inputs. I have used "plot" as you suggested:

set terminal png
set output "filename.png"
set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
pause 1
reread

but still it is showing following error:

plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
"Residuals", line 8: Bad data on line 1

I did go through some posts for plotting gnuplot for residuals and I have tried to do this as mentioned in the posts but still it is showing some error. Do you have any idea way it is coming?

Thanks,
Sangeeta

Tushar@cfd May 10, 2013 02:48

Quote:

Originally Posted by Sargam05 (Post 426407)
Hi Tushar,

Thank so much for the inputs. I have used "plot" as you suggested:

set terminal png
set output "filename.png"
set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
pause 1
reread

but still it is showing following error:

plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
"Residuals", line 8: Bad data on line 1

I did go through some posts for plotting gnuplot for residuals and I have tried to do this as mentioned in the posts but still it is showing some error. Do you have any idea way it is coming?

Thanks,
Sangeeta


Try these steps.. I always follow these for plotting residuals.


Open the case folder in your console window (terminal).

execute the $application (for eg. icoFoam or any $Foam which you are using) and simultaneously write a log file using the following command in the terminal:

$application >log


Then open gnuplot in the same console window, and execute the following command:

set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
pause 1
reread

I wish this will solve your problem.

Tushar@cfd May 10, 2013 03:02

Try to edit your output log file like the following and then follow the procedure as mentioned in my earlier post....


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading transportProperties

Reading field p

Reading field U

Reading/calculating face flux field phi


Starting time loop

Time: 1

Solving for U using DICPCG, Initial residual = 1, Final residual = 1, Relative residual = 59362.4, No outer iterations 1
ExecutionTime = 26.44 s ClockTime = 27 s
ExecutionTime = 26.6 s


Time: 2

Solving for U using DICPCG, Initial residual = 1, Final residual = 1, Relative residual = 1, No outer iterations 1
ExecutionTime = 37.93 s ClockTime = 38 s
ExecutionTime = 38.12 s


Time: 3

Solving for U using DICPCG, Initial residual = 0.305633, Final residual = 0.305633, Relative residual = 1, No outer iterations 1
ExecutionTime = 54.7 s ClockTime = 55 s
ExecutionTime = 54.9 s


Time: 4

Solving for U using DICPCG, Initial residual = 0.229696, Final residual = 0.229696, Relative residual = 1, No outer iterations 1
ExecutionTime = 66.4 s ClockTime = 67 s
ExecutionTime = 66.59 s


Time: 5

Solving for U using DICPCG, Initial residual = 0.155004, Final residual = 0.155004, Relative residual = 1, No outer iterations 1
ExecutionTime = 83.12 s ClockTime = 83 s
ExecutionTime = 83.3 s

Time: 6

Solving for U using DICPCG, Initial residual = 0.088822, Final residual = 0.088822, Relative residual = 1, No outer iterations 1
ExecutionTime = 96.02 s ClockTime = 96 s
ExecutionTime = 96.21 s


Time: 7

Solving for U using DICPCG, Initial residual = 0.0763407, Final residual = 0.0763407, Relative residual = 1, No outer iterations 1
ExecutionTime = 109.27 s ClockTime = 110 s
ExecutionTime = 109.45 s


Time: 8

Solving for U using DICPCG, Initial residual = 0.0426613, Final residual = 0.0426613, Relative residual = 1, No outer iterations 1
ExecutionTime = 121.37 s ClockTime = 122 s
ExecutionTime = 121.57 s

#########

I think that was the problem with your case, I hope now you are able to plot.
:)

Sargam05 May 10, 2013 13:35

2 Attachment(s)
Hi Tushar,

Thank you so much for the suggestions! I have edited some of the initial part of the log file and used the command you mentioned in gnuplot but it is still showing following error:

Terminal type set to 'wxt'
gnuplot> set logscale y
gnuplot> set title "Residuals"
gnuplot> set ylabel 'Residual'
gnuplot> set xlabel 'Iteration'
gnuplot> plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
Bad data on line 1

gnuplot> pause 1
gnuplot> reread

I do not know if something is wrong in logs file. I am also attaching the log and logs folders as attachment. Please let me know if something is wrong in these folders.

Best regards,
Sangeeta

Tushar@cfd May 11, 2013 03:00

Quote:

Originally Posted by Sargam05 (Post 426559)
Hi Tushar,

Thank you so much for the suggestions! I have edited some of the initial part of the log file and used the command you mentioned in gnuplot but it is still showing following error:

Terminal type set to 'wxt'
gnuplot> set logscale y
gnuplot> set title "Residuals"
gnuplot> set ylabel 'Residual'
gnuplot> set xlabel 'Iteration'
gnuplot> plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
Bad data on line 1

gnuplot> pause 1
gnuplot> reread

I do not know if something is wrong in logs file. I am also attaching the log and logs folders as attachment. Please let me know if something is wrong in these folders.

Best regards,
Sangeeta

Can you please upload the controlDict file?

billie May 11, 2013 06:24

Quote:

Originally Posted by Sargam05 (Post 426190)
Time: 8

Time 8, Corrector 0, Solving for U using DICPCG, residual = 0.0426613, relative residual = 1

Time 8, Solving for U, Initial residual = 0.0426613, Final residual = 0.0426613, Relative residual = 1, No outer iterations 1
ExecutionTime = 121.37 s ClockTime = 122 s
ExecutionTime = 121.57 s

Quote:

Originally Posted by Sargam05 (Post 426559)
gnuplot> plot "< cat log | grep 'Solving for U' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
Bad data on line 1

You grep for 'Solving for U' split by space and use the 9th field but as you can see there are different lines in your log file containing the grep string. The problem is for the line with the corrector the 9th field is "DICPCG" and gnuplot only works with numbers. You have restrict your grep string so it only matches the line with your residual.

Sargam05 May 11, 2013 15:13

1 Attachment(s)
Hi Tushar and Daniel,

Thank you for the reply. Tushar please find controlDict file as attachment.

Daniel even after changing the script based on log file following error is comping:

plot "< cat log | grep 'Solving for U using DICPCG' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
"Residuals", line 8: Bad data on line 1

billie May 11, 2013 15:42

Quote:

Originally Posted by Sargam05 (Post 426728)
Hi Tushar and Daniel,

Thank you for the reply. Tushar please find controlDict file as attachment.

Daniel even after changing the script based on log file following error is comping:

plot "< cat log | grep 'Solving for U using DICPCG' | cut -d' ' -f9 | tr -d ','" title 'U' with lines
^
"Residuals", line 8: Bad data on line 1

It is always a good idea to test this first in a console.

Check the output of:

Code:

cat log | grep 'Solving for U using DICPCG' | cut -d' ' -f9 | tr -d ','
It should give you a series of "DICPCG". This is because the line you are grepping for the residual is in field 12 and not in field 9. So you can either use
Code:

cat log | grep 'Solving for U using DICPCG' | cut -d' ' -f12 | tr -d ','
or
Code:

cat log | grep 'Solving for U,' | cut -d' ' -f9 | tr -d ','

Sargam05 May 11, 2013 22:37

Hi Daniel,

Thank you so much for the suggestions. Now it plotting residuals. I appreciate your help!

I also like to thank Tushar for his inputs.

Best regards,
Sangeeta

Tushar@cfd May 13, 2013 07:50

Quote:

Originally Posted by Sargam05 (Post 426771)
Hi Daniel,

Thank you so much for the suggestions. Now it plotting residuals. I appreciate your help!

I also like to thank Tushar for his inputs.

Best regards,
Sangeeta

It's good to see, you are getting your residual plots.

EmadTandis May 30, 2013 02:04

Hello everyone
for plotting residuals by gnuplot, I want to plot p-residuals for a special row of p-solver not every row. for example, in icoFoam, I want to plot initial residual for p for every time step not for evey pisoLoop.
Best Regards

gschaider May 30, 2013 06:22

Quote:

Originally Posted by EmadTandis (Post 430888)
Hello everyone
for plotting residuals by gnuplot, I want to plot p-residuals for a special row of p-solver not every row. for example, in icoFoam, I want to plot initial residual for p for every time step not for evey pisoLoop.
Best Regards

That is what pyFoamPlotWatcher.py from the PyFoam-utilities does out of the box (plot only the first residual of a timestep).

EmadTandis May 30, 2013 17:57

Thanks
but can you tell me about use of this utility?
for plotting residuals, I type " gnuplot plotInstruction" on terminal. that plotInstruction is a text file based on this forum.
can I do this by writing new thing in this file?

Best Regards
Emad Tandis

gschaider May 30, 2013 20:48

Quote:

Originally Posted by EmadTandis (Post 431062)
Thanks
but can you tell me about use of this utility?
for plotting residuals, I type " gnuplot plotInstruction" on terminal. that plotInstruction is a text file based on this forum.
can I do this by writing new thing in this file?

Best Regards
Emad Tandis

This utility analyzes the logfile and plots the residuals

Jibran July 1, 2014 08:51

pyFoam error on OpenFOAM Extend
 
Quote:

Originally Posted by gschaider (Post 430934)
That is what pyFoamPlotWatcher.py from the PyFoam-utilities does out of the box (plot only the first residual of a timestep).

Dear Bernhard,

This thread is related to OpenFOAM Extend in particular and I was getting an error running pyFoamPlotWatcher.py on Extend. I guess I need to make changes to extract data from log file correctly. Can you please point me in the right direction? The error is here: http://www.cfd-online.com/Forums/ope...tml#post498826

Thanks in advance!

Jibran

gschaider July 2, 2014 19:29

Quote:

Originally Posted by Jibran (Post 499470)
Dear Bernhard,

This thread is related to OpenFOAM Extend in particular and I was getting an error running pyFoamPlotWatcher.py on Extend. I guess I need to make changes to extract data from log file correctly. Can you please point me in the right direction? The error is here: http://www.cfd-online.com/Forums/ope...tml#post498826

Thanks in advance!

Jibran

That is a long thread and the permalink took me to an unrelated posting. Which post number?

Jibran July 3, 2014 07:59

Quote:

Originally Posted by gschaider (Post 499735)
That is a long thread and the permalink took me to an unrelated posting. Which post number?

Hmm, that is quite strange because it takes me directly to my post (#238 on last page of the thread)


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