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

Conditional array manipulation in order to avoid negative components

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 23, 2013, 12:09
Default Conditional array manipulation in order to avoid negative components
  #1
Member
 
Marcus Letzel
Join Date: Sep 2012
Location: Bremen
Posts: 35
Rep Power: 13
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:

Code:
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:
Code:
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,
Marcus
letzel 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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 17:22
2nd order boundary conditions for 2nd order discretization? quarkz Main CFD Forum 30 December 26, 2011 07:12
[CFX] How to avoid negative temperatures? rogbrito CFX 3 February 15, 2010 05:59
Turbo components order in Blade-to-Blade View Aladdin CFX 0 March 17, 2007 09:01
hankel negative order sankar Main CFD Forum 1 June 16, 2006 06:12


All times are GMT -4. The time now is 23:25.