CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Cube root in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By anon_q

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 2, 2019, 08:38
Default Cube root in OpenFOAM
  #1
New Member
 
Join Date: Jun 2019
Posts: 17
Rep Power: 6
zcheng is on a distinguished road
Hello everyone,

Does anyone knows how to put cube root in OpenFOAM?
zcheng is offline   Reply With Quote

Old   July 5, 2019, 08:59
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Yes, this is quite straightforward. Knowing that we can calculate the square root of something e.g. x with :

Code:
sqrtX = sqrt(x)
we might guess that foam would use similar abbreviation for the cube root. So we guess that cbrt is likely and search the code for "cbrt" and see many matches. You could try computing a cube root of x as :

Code:
cbrtX = cbrt(x)
I've not used this myself before, so be sure to make sure it does what we expect. Another straightforward option that I use sometimes is the pow function :

Code:
cbrtX = pow(x,1.0/3.0)
Caelan
clapointe is offline   Reply With Quote

Old   July 5, 2019, 09:42
Default
  #3
New Member
 
Join Date: Jun 2019
Posts: 17
Rep Power: 6
zcheng is on a distinguished road
Thanks a lot!
zcheng is offline   Reply With Quote

Old   July 5, 2019, 09:43
Default
  #4
Senior Member
 
Join Date: Mar 2018
Posts: 115
Rep Power: 8
anon_q is on a distinguished road
For a more safe result (including negative numbers) you can use the following:



Code:
 // calculate the cube root of abs(x)
cbrtAbsX = pow(abs(x), 1.0/3.0)
 // the cube root is returned according to the sign of x
cbrtX = (x < 0)? -cbrtAbsX:cbrtAbsX
randon likes this.
anon_q is offline   Reply With Quote

Old   July 5, 2019, 10:24
Default
  #5
New Member
 
Join Date: Jun 2019
Posts: 17
Rep Power: 6
zcheng is on a distinguished road
Thanks for the suggestion!
zcheng is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFOAM course for beginners Jibran OpenFOAM Announcements from Other Sources 2 November 4, 2019 08:51
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 15:54
[snappyHexMesh] snappyHexMesh on sharp corners (cube) Regis_ OpenFOAM Meshing & Mesh Conversion 0 June 4, 2015 23:47
[OpenFOAM.org] How to get OpenFoam compiled on a cluster with CentOS 6.5 and no root permissions hulli OpenFOAM Installation 2 November 6, 2014 18:01
Environment errors with .deb install and ubuntu 13.04 64 bit jonathanbyrn OpenFOAM Installation 14 September 26, 2013 05:22


All times are GMT -4. The time now is 14:48.