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

OpenFOAM 4.x: pow function cause floating point error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 11, 2016, 09:13
Default OpenFOAM 4.x: pow function cause floating point error
  #1
New Member
 
SSSSS
Join Date: Jun 2011
Posts: 28
Rep Power: 14
doctorWho is on a distinguished road
Hi,

I want to do some calculation with point coordinate with pow function.

The code is roughly as follows:


Code:
const pointMesh& pMesh = pointMesh::New(mesh);
        vectorField coord = this->points0();
        scalarField sf(this->points0().size());

        forAll(sf, pointi)
        {
             sf[pointi] = pow(coord[pointi].x(), 0.6);
        }
I have searched several threads about pow function of OpenFOAM. I have tried Foam:: pow instead pow without any success.

when the exponent is integer type e.g., 2 instead of 0.6, then it works.
The problem is always when the exponent is scalar type or float type.
Any advice?
doctorWho is offline   Reply With Quote

Old   September 11, 2016, 09:48
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: My guess is that you have "x" values that are negative. For example:
Code:
pow(a,0.5)
is the same as:
Code:
sqrt(a)
so if "a" is negative, the answer is a complex number, not a real number, hence the crash.
__________________
wyldckat is offline   Reply With Quote

Old   September 11, 2016, 10:36
Default
  #3
New Member
 
SSSSS
Join Date: Jun 2011
Posts: 28
Rep Power: 14
doctorWho is on a distinguished road
Yes, you are right. Thanks alot.
doctorWho is offline   Reply With Quote

Reply

Tags
openfoam


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
Running UDF with Supercomputer roi247 FLUENT 4 October 15, 2015 13:41
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 06:42
Installation OF1.5-dev ttdtud OpenFOAM Installation 46 May 5, 2009 02:32
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50
[Gmsh] Gmsh and samplesurface touf OpenFOAM Meshing & Mesh Conversion 2 December 10, 2007 02:27


All times are GMT -4. The time now is 02:11.