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

Conditional array manipulation in order to avoid negative components

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

LinkBack Thread Tools Display Modes
Old   October 23, 2013, 12:09
Default Conditional array manipulation in order to avoid negative components
Marcus Letzel
Join Date: Sep 2012
Location: Aurich
Posts: 35
Rep Power: 5
letzel is on a distinguished road
Dear Foamers,

in a modified LES solver, I calculate the turbulence intensity Iav from Uav and U2av as follows:

Uav  = ( Uav*(time-startAveraging) + U*dt ) / (time-startAveraging + dt);
for ( int i = 1; i <= 3; ++i)
  U2av.component(i) = ( U2av.component(i)*(time-startAveraging) + sqr(U.component(i))*dt ) / (time-startAveraging + dt);
for ( int i = 1; i <= 3; ++i)
  Iav.component(i) = sqrt( U2av.component(i) - sqr( Uav.component(i) ) ) / ( mag(Uav)+magUTinyOffset );  // avoid zero division
The term U2av.component(i) - sqr( Uav.component(i) ) may be negative, which then causes a fatal floating point error on calculation of its square root. I would like to set the term to zero in such cases, but don't know how to achieve this.

In Fortran, the WHERE function lets you conditionally manipulate arrays:
WHERE(array<0.0) array=0.0
Does OpenFOAM offer a similar functionality, or C++? If so, could you please explain how to use it?

Best regards,
letzel is offline   Reply With Quote


Thread Tools
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
2nd order boundary conditions for 2nd order discretization? quarkz Main CFD Forum 30 December 26, 2011 08:12
mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 12 December 12, 2011 05:16
[CFX] How to avoid negative temperatures? rogbrito CFX 3 February 15, 2010 06:59
Turbo components order in Blade-to-Blade View Aladdin CFX 0 March 17, 2007 10:01
hankel negative order sankar Main CFD Forum 1 June 16, 2006 06:12

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