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/)
-   -   How to plot pitch motion for free decay test? (https://www.cfd-online.com/Forums/openfoam-post-processing/170471-how-plot-pitch-motion-free-decay-test.html)

mo_na May 2, 2016 06:15

How to plot pitch motion for free decay test?
 
Hi all,

I am simulating a floating body in pitch motion and I would like to do a free decay test to compare with experimental results.
I am using a moving mesh and the log file contains information like this:
Code:

6-DoF rigid body motion
    Centre of rotation: (0 0 0)
    Centre of mass: (0.58783434026 0 -0.181372871211)
    Orientation: (0.995632340385 0 0.0933608203665 0 1 0 -0.0933608203665 0 0.995632340385)
    Linear velocity: (0 0 0)
    Angular velocity: (0 0.0586546346079 0)

Is there a way to write the orientation of the body in a separate file to plot the pitch motion after? Or is there maybe another way?

Cheers,
Mona

hchen May 23, 2016 04:27

Hi Mona:

Did you manage to do it?

Best regards
Hao


Quote:

Originally Posted by mo_na (Post 597674)
Hi all,

I am simulating a floating body in pitch motion and I would like to do a free decay test to compare with experimental results.
I am using a moving mesh and the log file contains information like this:
Code:

6-DoF rigid body motion
    Centre of rotation: (0 0 0)
    Centre of mass: (0.58783434026 0 -0.181372871211)
    Orientation: (0.995632340385 0 0.0933608203665 0 1 0 -0.0933608203665 0 0.995632340385)
    Linear velocity: (0 0 0)
    Angular velocity: (0 0.0586546346079 0)

Is there a way to write the orientation of the body in a separate file to plot the pitch motion after? Or is there maybe another way?

Cheers,
Mona


mo_na May 24, 2016 04:40

Hi Hao,

no I havn't managed yet. Do you have an idea how to do it or do you want me to tell you as soon as I figured it out? :)

Cheers,
Mona

mo_na May 27, 2016 06:45

Ideas
 
Hi all,

I have some ideas now how to do it but I am not quite there yet.
In this thread simon-2 describes a way to obtain sixDoFRigidBodyMotionState files for each timestep:
http://www.cfd-online.com/Forums/ope...tml#post601930
He said it was just a matter of batch processing to write all the information into one file so you obtain a file like this:
Code:

#time centreOfMass orientation velocity acceleration angularMomentum Torque
80.0199 ( 3.3 0 0.1386375 ) ( 0.99807619 0 0.061999301 0 1 0 -0.061999301 0 0.99807619 ) ( 0 0 0.0045163445 ) ( 1.3211615 -2.6233042 0.84606626 ) ( 0 -0.2529557 0 ) ( 1109.8274 99.511973 -24.488035 )
80.0298 ( ... ... ... ) (.. ... ... .. .. .. .. .. ..) (.. .. ..) (.. .. ..) (... .. ..)
80.0398 ( ... ... ... ) (.. ... ... .. .. .. .. .. ..) (.. .. ..) (.. .. ..) (... .. ..)
80.0497 ( ... ... ... ) (.. ... ... .. .. .. .. .. ..) (.. .. ..) (.. .. ..) (... .. ..)

But I havn't figured out how to do it.
I also found this python-script: https://github.com/kodejak/openfoam-data-extractor
This script extracts searched datas from the OpenFOAM project generated files e.g. gravity, centreOfMass etc. The datas will be stored as a CSV file located at the directory of the script, named like the command line search pattern.
But then I still need to do this for every single sixDoFRigidBodyMotionState file and thats a lot.
Any ideas?

Cheers,
Mona

mo_na June 1, 2016 10:51

Solved
 
Hey,

for everyone struggling with the same issue: I found a shell script that writes out data from the logfile and modified it a little bit to match my needs:
Code:

#!/bin/bash

PFAD=log
EXCL=10

# cat  list a files content on a screen / in a pipeline (using "|")
# grep  returns all lines matching a certain string
# cut  cuts out e.g. fields "-f" (here 3rd until END [-]) specified through delminiter "-d' '" (here blanks)
# sed  remove complete lines containing a certain string (here "ClockTime")
# sed-i includes Header
# head  deletes last 10 lines (for scaling reasons, as last lines are often already diverged)
# tr    remove certain strings (here "(" and ")")
#paste  merge two files line by line

################ CLEAR OLD DATA ################
rm -r data

##################### TIME #####################
cat $PFAD | grep 'Time = ' | cut -d' ' -f3- | sed '/ClockTime/d' > Time.dat

############### ORIENTATION  ###############
cat $PFAD | grep 'Orientation' | cut -d' ' -f3- | tr -d '(' | tr -d ')'| tr -d 'Orientation:' | sed -e 's/[\\ \\]/      /g' > orientationTemp.dat

############### LINEAR VELOCITY ################
cat $PFAD | grep 'Linear velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/        /g' > linearVelocityTemp.dat

############### ANGULAR VELOCITY ###############
cat $PFAD | grep 'Angular velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/      /g' > angularVelocityTemp.dat

########## MERGE FILES & ADD HEADER ############
mkdir data
paste Time.dat orientationTemp.dat > data/orientationTemp.dat
sed -i '1i#Time, cos, 0, sin, 0, 1, 0, -sin, 0, cos' data/orientationTemp.dat
head -n -$EXCL data/orientationTemp.dat > data/orientation.dat
paste Time.dat linearVelocityTemp.dat > data/linearVelocityTemp.dat
sed -i '1i#Time, u, v, w' data/linearVelocityTemp.dat
head -n -$EXCL data/linearVelocityTemp.dat > data/linearVelocity.dat
paste Time.dat angularVelocityTemp.dat > data/angularVelocityTemp.dat
sed -i '1i#Time, p, q, r' data/angularVelocityTemp.dat
head -n -$EXCL data/angularVelocityTemp.dat > data/angularVelocity.dat
rm Time.dat
rm orientationTemp.dat
rm data/orientationTemp.dat
rm linearVelocityTemp.dat
rm data/linearVelocityTemp.dat
rm angularVelocityTemp.dat
rm data/angularVelocityTemp.dat
rm plot/*.png

So copy this code into a file called data.sh and execute after running simulation with
Code:

bash data.sh
This will write you some .dat files, that you can open/plot with matlab/ocatve/excel/whatever

I hoped this will help someone! :)
Cheers,
Mona

havref November 23, 2016 05:04

Exactly what I have been searching for. Thanks!

Adri_12 October 16, 2018 12:09

Hi Mona,

I am using the new rigidBodyDynamics library instead of the classical sixDofRigidBodyMotion ?

The problem is that I do not understand how to explore the log file info since the CoG is not logged out anymore. What we have instead is a "center of rotation" but it is not the kind of point I am looking for, a CoG or a manually point to follow would be better. Here you have an example :

Code:

Courant Number mean: 0.000365065 max: 0.934088
Interface Courant Number mean: 1.39805e-05 max: 0.301043
deltaT = 0.00981865
Time = 2.43733

PIMPLE: iteration 1
forces forces:
    Not including porosity effects
Rigid-body motion of the BOAT
    Centre of rotation: (0.148519 -3.25435e-06 -0.00757061)
    Orientation: (0.999997 2.91458e-07 0.0022597 -2.91323e-07 1 -6.00382e-08 -0.0022597 5.93798e-08 0.999997)
    Linear velocity: (0.0538253 3.10699e-06 0.0702008)

Moreover, a "q" 6 dimension vector is automatically copied in the folder /uniform/rigidBodyState that seems to match with the log point info.

If you have some info about the way to extract CoG info, please share it ;)

Adri

Robin86 December 22, 2018 08:38

Quote:

Originally Posted by mo_na (Post 602859)
Hey,

for everyone struggling with the same issue: I found a shell script that writes out data from the logfile and modified it a little bit to match my needs:
Code:

#!/bin/bash

PFAD=log
EXCL=10

# cat  list a files content on a screen / in a pipeline (using "|")
# grep  returns all lines matching a certain string
# cut  cuts out e.g. fields "-f" (here 3rd until END [-]) specified through delminiter "-d' '" (here blanks)
# sed  remove complete lines containing a certain string (here "ClockTime")
# sed-i includes Header
# head  deletes last 10 lines (for scaling reasons, as last lines are often already diverged)
# tr    remove certain strings (here "(" and ")")
#paste  merge two files line by line

################ CLEAR OLD DATA ################
rm -r data

##################### TIME #####################
cat $PFAD | grep 'Time = ' | cut -d' ' -f3- | sed '/ClockTime/d' > Time.dat

############### ORIENTATION  ###############
cat $PFAD | grep 'Orientation' | cut -d' ' -f3- | tr -d '(' | tr -d ')'| tr -d 'Orientation:' | sed -e 's/[\\ \\]/      /g' > orientationTemp.dat

############### LINEAR VELOCITY ################
cat $PFAD | grep 'Linear velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/        /g' > linearVelocityTemp.dat

############### ANGULAR VELOCITY ###############
cat $PFAD | grep 'Angular velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/      /g' > angularVelocityTemp.dat

########## MERGE FILES & ADD HEADER ############
mkdir data
paste Time.dat orientationTemp.dat > data/orientationTemp.dat
sed -i '1i#Time, cos, 0, sin, 0, 1, 0, -sin, 0, cos' data/orientationTemp.dat
head -n -$EXCL data/orientationTemp.dat > data/orientation.dat
paste Time.dat linearVelocityTemp.dat > data/linearVelocityTemp.dat
sed -i '1i#Time, u, v, w' data/linearVelocityTemp.dat
head -n -$EXCL data/linearVelocityTemp.dat > data/linearVelocity.dat
paste Time.dat angularVelocityTemp.dat > data/angularVelocityTemp.dat
sed -i '1i#Time, p, q, r' data/angularVelocityTemp.dat
head -n -$EXCL data/angularVelocityTemp.dat > data/angularVelocity.dat
rm Time.dat
rm orientationTemp.dat
rm data/orientationTemp.dat
rm linearVelocityTemp.dat
rm data/linearVelocityTemp.dat
rm angularVelocityTemp.dat
rm data/angularVelocityTemp.dat
rm plot/*.png

So copy this code into a file called data.sh and execute after running simulation with
Code:

bash data.sh
This will write you some .dat files, that you can open/plot with matlab/ocatve/excel/whatever

I hoped this will help someone! :)
Cheers,
Mona


Hi, Mona!
I also try to plot the heave motion of a floating body. I follow your ideas above. After running the case, I creat a file named data.sh and copy the script into the this file. Then I run the command bash data.sh in the terminal. However, some errors happen and I get three .dat files without nothong in these files. I don't know if I am right to do so. Did I do someting wrong so that I can't get the data.
I am new here. I wish your rely, thank you!

Fieschi February 27, 2019 10:27

Hi Robin86,

Quote:

Originally Posted by Robin86 (Post 719892)
I get three .dat files without nothong in these files.

Try to personalise the data file by modifying the following line :
Code:

PFAD=log
For example, if your data are written in a file called log.interFoam you have to write :
Code:

PFAD=log.interFoam
Regards,
Laurent.

Robin86 March 19, 2019 20:28

Thank you for your reply. I already fix the problem.

AR91 September 30, 2019 07:01

Quote:

Originally Posted by mo_na (Post 602859)
Hey,

for everyone struggling with the same issue: I found a shell script that writes out data from the logfile and modified it a little bit to match my needs:
Code:

#!/bin/bash

PFAD=log
EXCL=10

# cat  list a files content on a screen / in a pipeline (using "|")
# grep  returns all lines matching a certain string
# cut  cuts out e.g. fields "-f" (here 3rd until END [-]) specified through delminiter "-d' '" (here blanks)
# sed  remove complete lines containing a certain string (here "ClockTime")
# sed-i includes Header
# head  deletes last 10 lines (for scaling reasons, as last lines are often already diverged)
# tr    remove certain strings (here "(" and ")")
#paste  merge two files line by line

################ CLEAR OLD DATA ################
rm -r data

##################### TIME #####################
cat $PFAD | grep 'Time = ' | cut -d' ' -f3- | sed '/ClockTime/d' > Time.dat

############### ORIENTATION  ###############
cat $PFAD | grep 'Orientation' | cut -d' ' -f3- | tr -d '(' | tr -d ')'| tr -d 'Orientation:' | sed -e 's/[\\ \\]/      /g' > orientationTemp.dat

############### LINEAR VELOCITY ################
cat $PFAD | grep 'Linear velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/        /g' > linearVelocityTemp.dat

############### ANGULAR VELOCITY ###############
cat $PFAD | grep 'Angular velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/      /g' > angularVelocityTemp.dat

########## MERGE FILES & ADD HEADER ############
mkdir data
paste Time.dat orientationTemp.dat > data/orientationTemp.dat
sed -i '1i#Time, cos, 0, sin, 0, 1, 0, -sin, 0, cos' data/orientationTemp.dat
head -n -$EXCL data/orientationTemp.dat > data/orientation.dat
paste Time.dat linearVelocityTemp.dat > data/linearVelocityTemp.dat
sed -i '1i#Time, u, v, w' data/linearVelocityTemp.dat
head -n -$EXCL data/linearVelocityTemp.dat > data/linearVelocity.dat
paste Time.dat angularVelocityTemp.dat > data/angularVelocityTemp.dat
sed -i '1i#Time, p, q, r' data/angularVelocityTemp.dat
head -n -$EXCL data/angularVelocityTemp.dat > data/angularVelocity.dat
rm Time.dat
rm orientationTemp.dat
rm data/orientationTemp.dat
rm linearVelocityTemp.dat
rm data/linearVelocityTemp.dat
rm angularVelocityTemp.dat
rm data/angularVelocityTemp.dat
rm plot/*.png

So copy this code into a file called data.sh and execute after running simulation with
Code:

bash data.sh
This will write you some .dat files, that you can open/plot with matlab/ocatve/excel/whatever

I hoped this will help someone! :)
Cheers,
Mona

There seems to be an issue when this script copies exponents from the log file to the .dat file.
For instance: 1.34587e-18 becomes 1.34587-18.
Any help would be greatly appreciated in this regard.
Thanks,
Arun.

quarkz February 4, 2022 20:31

Quote:

Originally Posted by AR91 (Post 745861)
There seems to be an issue when this script copies exponents from the log file to the .dat file.
For instance: 1.34587e-18 becomes 1.34587-18.
Any help would be greatly appreciated in this regard.
Thanks,
Arun.

Hi Arun,

Just saw your msg. Actually the reason this occurs is due to:

Code:

tr -d 'Orientation:'
All the "e" are removed. Hence, you can remove that part. The word "Orientation" will be in the extracted data though.

zyfsoton March 18, 2022 11:31

Dear all,

I have the same question about this pitch and heave plot.

I think the sin(pitch) is the third component of the orientation vector but I have no idea how to derive the heave.

Please let me know if you have any ideas.

Many thanks,
Tony

Brandon_ February 19, 2023 21:31

Quote:

Originally Posted by Adri_12 (Post 710235)
Hi Mona,

I am using the new rigidBodyDynamics library instead of the classical sixDofRigidBodyMotion ?

The problem is that I do not understand how to explore the log file info since the CoG is not logged out anymore. What we have instead is a "center of rotation" but it is not the kind of point I am looking for, a CoG or a manually point to follow would be better. Here you have an example :

Code:

Courant Number mean: 0.000365065 max: 0.934088
Interface Courant Number mean: 1.39805e-05 max: 0.301043
deltaT = 0.00981865
Time = 2.43733

PIMPLE: iteration 1
forces forces:
    Not including porosity effects
Rigid-body motion of the BOAT
    Centre of rotation: (0.148519 -3.25435e-06 -0.00757061)
    Orientation: (0.999997 2.91458e-07 0.0022597 -2.91323e-07 1 -6.00382e-08 -0.0022597 5.93798e-08 0.999997)
    Linear velocity: (0.0538253 3.10699e-06 0.0702008)

Moreover, a "q" 6 dimension vector is automatically copied in the folder /uniform/rigidBodyState that seems to match with the log point info.

If you have some info about the way to extract CoG info, please share it ;)

Adri

Hello.Recently, I am using the rigidbodymotion solver instead of SixDoFrigidbodymotion,too. I want to solve the center of mass and six degrees of freedom of the floating body and face the same problem with you. Do you have any good ideas?
Many thanks,
Brandon

Ramesh mukkund February 25, 2024 08:57

forgot
Quote:

Originally Posted by mo_na (Post 602859)
Hey,

for everyone struggling with the same issue: I found a shell script that writes out data from the logfile and modified it a little bit to match my needs:
Code:

#!/bin/bash

PFAD=log
EXCL=10

# cat  list a files content on a screen / in a pipeline (using "|")
# grep  returns all lines matching a certain string
# cut  cuts out e.g. fields "-f" (here 3rd until END [-]) specified through delminiter "-d' '" (here blanks)
# sed  remove complete lines containing a certain string (here "ClockTime")
# sed-i includes Header
# head  deletes last 10 lines (for scaling reasons, as last lines are often already diverged)
# tr    remove certain strings (here "(" and ")")
#paste  merge two files line by line

################ CLEAR OLD DATA ################
rm -r data

##################### TIME #####################
cat $PFAD | grep 'Time = ' | cut -d' ' -f3- | sed '/ClockTime/d' > Time.dat

############### ORIENTATION  ###############
cat $PFAD | grep 'Orientation' | cut -d' ' -f3- | tr -d '(' | tr -d ')'| tr -d 'Orientation:' | sed -e 's/[\\ \\]/      /g' > orientationTemp.dat

############### LINEAR VELOCITY ################
cat $PFAD | grep 'Linear velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/        /g' > linearVelocityTemp.dat

############### ANGULAR VELOCITY ###############
cat $PFAD | grep 'Angular velocity' | cut -d' ' -f3- | tr -d '(' | tr -d ')' | sed -e 's/[\\ \\]/      /g' > angularVelocityTemp.dat

########## MERGE FILES & ADD HEADER ############
mkdir data
paste Time.dat orientationTemp.dat > data/orientationTemp.dat
sed -i '1i#Time, cos, 0, sin, 0, 1, 0, -sin, 0, cos' data/orientationTemp.dat
head -n -$EXCL data/orientationTemp.dat > data/orientation.dat
paste Time.dat linearVelocityTemp.dat > data/linearVelocityTemp.dat
sed -i '1i#Time, u, v, w' data/linearVelocityTemp.dat
head -n -$EXCL data/linearVelocityTemp.dat > data/linearVelocity.dat
paste Time.dat angularVelocityTemp.dat > data/angularVelocityTemp.dat
sed -i '1i#Time, p, q, r' data/angularVelocityTemp.dat
head -n -$EXCL data/angularVelocityTemp.dat > data/angularVelocity.dat
rm Time.dat
rm orientationTemp.dat
rm data/orientationTemp.dat
rm linearVelocityTemp.dat
rm data/linearVelocityTemp.dat
rm angularVelocityTemp.dat
rm data/angularVelocityTemp.dat
rm plot/*.png

So copy this code into a file called data.sh and execute after running simulation with
Code:

bash data.sh
This will write you some .dat files, that you can open/plot with matlab/ocatve/excel/whatever

I hoped this will help someone! :)
Cheers,
Mona

Hi mona,
I'm running floatingObject (2d case) using olaFlow and I'm able to run simulation successfully. while i was trying to plot surge, heave plot i used your script with just modifying 'log' to 'olaDyMFoam.log' , and then running ' bash data.sh' , i got this msg. I couldn't get this msg what I'm doing wrong. can u please help me to figure it out.
this is what i got after running 'bash data.sh'

https://prnt.sc/6p2lCfU9ASfm

Ramesh mukkund February 25, 2024 09:00

Quote:

Originally Posted by Ramesh mukkund (Post 865273)
forgot
Hi mona,
I'm running floatingObject (2d case) using olaFlow and I'm able to run simulation successfully. while i was trying to plot surge, heave plot i used your script with just modifying 'log' to 'olaDyMFoam.log' , and then running ' bash data.sh' , i got this msg. I couldn't get this msg what I'm doing wrong. can u please help me to figure it out.
this is what i got after running 'bash data.sh'

https://prnt.sc/6p2lCfU9ASfm

ramesh@DESKTOP-L0H8LQ0:~/olaFlow/tutorials/Floating_barge$ bash data.sh
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
paste: CentreofmassTemp.dat: No such file or directory
rm: cannot remove 'CentreofmassTemp.dat': No such file or directory
rm: cannot remove 'plot/*.png': No such file or directory

Ramesh mukkund February 25, 2024 15:29

Quote:

Originally Posted by Ramesh mukkund (Post 865274)
ramesh@DESKTOP-L0H8LQ0:~/olaFlow/tutorials/Floating_barge$ bash data.sh
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
cat: olaDyMFlow.log: No such file or directory
paste: CentreofmassTemp.dat: No such file or directory
rm: cannot remove 'CentreofmassTemp.dat': No such file or directory
rm: cannot remove 'plot/*.png': No such file or directory

issue solved.


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