CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Plotting max aspect ratio with time (https://www.cfd-online.com/Forums/openfoam-post-processing/253908-plotting-max-aspect-ratio-time.html)

2538sukham January 9, 2024 07:58

Plotting max aspect ratio with time
 
1 Attachment(s)
Hello Foamers.

I am running a dynamic simulation with a moving wall and velocity laplacian. I want to check the motion before the actual simulation and so moveDynamicMesh is performed. I have the mesh quality information for the time steps.



1. How do I plot the max aspect ratio with time for the mesh motion? I want to find at which timestep, the max aspect ratio is at a peak. I am at a lost.

2. checkMesh -writeAllFields have given me the required data and can be visualised via paraView. Is there a way to generate the plot from paraView?



I hope someone can point me to a right direction for the plot. Meanwhile if I come up with a solution, I will be happy to share it here


An instance of the simulation is attached.



With regards

NotOverUnderated January 9, 2024 08:22

According to your screenshot, the mesh quality fields including aspect ratio are written to disk every time step. You can open them in Paraview, and plot the maximum aspect ratio over time.

If you save the output from your screenshot to a log file you can use grep command to find the maximum aspect ratio. save it to a file and plot it.

2538sukham January 9, 2024 09:55

1 Attachment(s)
Quite right. I got it by following the following instruction given on
HTML Code:

https://docs.paraview.org/en/latest/Tutorials/ClassroomTutorials/beginningPlotting.html
Here is an image attached for the graph. Although it is a bit heavy on the system considering paraView have to look into every cell and write out the selection over time.



Thanks!

NotOverUnderated January 9, 2024 10:25

Nice :)

You can also use grep command to extract those values from the log file and plot them later using Gnuplot or any other software.

2538sukham January 9, 2024 10:48

I will do that and post the commands here after I successfully plot using grep.
Cheers. 🙂

2538sukham January 10, 2024 06:40

1 Attachment(s)
Here is the use of grep but then how to set the x axis as time and not iterations? The time was from 1s so the graph looks a bit different but then the plotting way would remain same.
Code:

set border lw 1
set logscale y
set title "Residuals" font "arial,16"
set ylabel "Aspect Ratio" font "arial,12"
set xlabel "Iterations" font "arial,12"
set key width 1
plot "< cat log | grep 'Max aspect ratio' | cut -d' ' -f9 | tr -d ','" title 'AspectRatio' with lines lw 1,
pause 1
reread

gnuplot Residuals.txt


How to get x axis as time??? hmmm.

NotOverUnderated January 10, 2024 07:02

Quote:

Originally Posted by 2538sukham (Post 862880)
Here is the use of grep but then how to set the x axis as time and not iterations? The time was from 1s so the graph looks a bit different but then the plotting way would remain same.
Code:

set border lw 1
set logscale y
set title "Residuals" font "arial,16"
set ylabel "Aspect Ratio" font "arial,12"
set xlabel "Iterations" font "arial,12"
set key width 1
plot "< cat log | grep 'Max aspect ratio' | cut -d' ' -f9 | tr -d ','" title 'AspectRatio' with lines lw 1,
pause 1
reread

gnuplot Residuals.txt


How to get x axis as time??? hmmm.

Nice!

I have some comments:

1) Do not cat to grep! Most commands accept filenames as arguments. So instead of:

Code:

cat filename | grep 'foo'
You should do this:

Code:

grep 'foo' filename

2) Instead of using the command inside gnuplot script, you can proceed like this:
  • use grep to extract Time from the file and save the result to a temporary file time.txt
  • use grep to extract the maximum aspect ratio from the file and save the result to a temporary file maxAspectRatio.txt
  • Use another tool to combine the two files into single file

To combine the two files time.txt and maxAspectRatio.txt you can use many tools: LibreOffice calc, Microsoft Excel, or a command with the name 'paste':

Code:

paste -d " " time.txt maxAspectRatio.txt > result.txt
The output file result.txt will have two columns: time and maxAspectRatio. Use that file in Gnuplot to plot it.


I know there are better ways to do that, but I hope this helps

2538sukham January 10, 2024 07:06

okay now I think I can accomplish this. I will post the result once this is done for other users if they need it. And Thank you for the input!! Really appreciated. :)
P.S. I am also looking into swak4Foam and pyFoam so if I get the alternatives, I will post here for other users. Cheers!

2538sukham January 12, 2024 21:10

1 Attachment(s)
So pyFoamPlotRunner.py can be used. or run the moveDynamicMesh > log and use
Code:

pyFoamPlotWatcher.py log --hardcopy --format-of-hardcopy=png
It prints out the non-orthogonality and aspect ratio with time.


I consider my thread closed. Thanks!


All times are GMT -4. The time now is 01:16.