# Problem with passing scalars from a field to an array

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

 November 8, 2011, 11:28 Problem with passing scalars from a field to an array #1 Senior Member     Hisham Elsafti Join Date: Apr 2011 Location: Braunschweig, Germany Posts: 249 Blog Entries: 10 Rep Power: 9 Dear Foamers, I have this bug that I can't figure out! Three scalar fields are read from a dictionary: Code: ```// Override the Ux and Uy Gains OverrideFreq (0.1 0.2 0.3 0.4 0.5); GainUx (5 5 6 7 8); GainUy (6 6 6 9 3);``` Then values of scalars from the field are passed to a dynamic array using: Code: ``` Info << "Freq = "<

 November 8, 2011, 12:27 #2 Senior Member   David Gaden Join Date: Apr 2009 Location: Winnipeg, Canada Posts: 436 Rep Power: 14 Info is probably formatting away the extra decimals. You are comparing double precision float numbers and you want an exact match? Try instead to take a difference: Code: ```// instead of: if (double(OverrideFreq[fi]) == double(filterFreqs_ [i])) // use: if ( (double(OverrideFreq[fi]) - double(filterFreqs_[i])) < SMALL // or something even smaller - but not VSMALL )``` __________________ ~~~ Follow me on twitter @DavidGaden

 November 8, 2011, 17:32 #3 Senior Member     Hisham Elsafti Join Date: Apr 2011 Location: Braunschweig, Germany Posts: 249 Blog Entries: 10 Rep Power: 9 Hi David, This solved it. Thanks a lot. just to complete the picture: Code: ```if (abs(value-value)

 November 8, 2011, 17:35 #4 Senior Member   David Gaden Join Date: Apr 2009 Location: Winnipeg, Canada Posts: 436 Rep Power: 14 Right... forgot about the absolute value. I'd suggest using OpenFOAM's built-in mag() function instead of abs()... just because I think it is more "type-safe"... __________________ ~~~ Follow me on twitter @DavidGaden

 Tags scalar array, scalarfield

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Toorop OpenFOAM Post-Processing 16 March 14, 2016 04:25 JFDC FLUENT 1 July 11, 2011 05:59 eelcovv OpenFOAM 0 June 8, 2010 11:35 Gabriele Velenich Main CFD Forum 5 December 11, 2001 04:43 Mikhail Main CFD Forum 40 September 9, 1999 09:11

All times are GMT -4. The time now is 00:40.