CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Abs function in OpenFOAM

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   October 19, 2021, 12:42
Default Abs function in OpenFOAM
New Member
Join Date: Feb 2021
Posts: 24
Rep Power: 3
NotOverUnderated is on a distinguished road
I am using OpenFOAM 7 to program a custom function object. Somewhere in the code, I needed to compute the absolute value of a scalar.

The code never worked as expected, and I had to spend approximately 2 hours in order to find the bug which turns out to be:

abs doesn't return the absolute value. for example abs(5.222) will always return 5.

* I am wondering why abs function in OpenFOAM behaves like that? what is the purpose? (unless I am missing something, I find it misleading).

* How to compute the absolute value of a scalar in OpenFOAM? (I know I can do: value = (value < 0)? -value: value) but I would like to know if there is a function to do that)

BTW, I needed to use abs from cmath which returns the expected value.

Could you please explain that?

Thank you


To compute the absolute value of a scalar in OpenFOAM use mag function, e.g mag(-7.556) will return 7.556.

Last edited by NotOverUnderated; October 19, 2021 at 14:36.
NotOverUnderated is offline   Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 07:15
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 15:54
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
[blockMesh] Errors during blockMesh meshing Madeleine P. Vincent OpenFOAM Meshing & Mesh Conversion 51 May 30, 2016 10:51

All times are GMT -4. The time now is 21:26.