|
[Sponsors] |
Problem with passing scalars from a field to an array |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
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: 257
Blog Entries: 10
Rep Power: 17 |
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); Code:
Info << "Freq = "<<filterFreqs_[i] << endl; forAll(OverrideFreq, fi) { Info << (OverrideFreq[fi])<< endl ; if (double(OverrideFreq[fi]) == double(filterFreqs_ [i])) { realGainUx_[i] = GainUx[fi]; realGainUy_[i] = GainUy[fi]; Info << " Condition Met : " << GainUx[fi] << " " << GainUy[fi] << endl; } } Info << "Real Gain Ux = " << realGainUx_[i] << " Freq = " << filterFreqs_[i] << endl; Code:
Freq = 0.1 0.1 Condition Met : 5 6 0.2 0.3 0.4 0.5 Real Gain Ux = 5 Freq = 0.1 Freq = 0.2 0.1 0.2 Condition Met : 5 6 0.3 0.4 0.5 Real Gain Ux = 5 Freq = 0.2 Freq = 0.3 0.1 0.2 0.3 0.4 0.5 Real Gain Ux = 0 Freq = 0.3 Freq = 0.4 0.1 0.2 0.3 0.4 Condition Met : 7 9 0.5 Real Gain Ux = 7 Freq = 0.4 Freq = 0.5 0.1 0.2 0.3 0.4 0.5 Condition Met : 8 3 Real Gain Ux = 8 Freq = 0.5 I fail to see what may be the problem! Best regards, Hisham |
|
November 8, 2011, 12:27 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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:35 |
|
#4 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
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 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
execFlowFunctionObjects - unknown field problem | Toorop | OpenFOAM Post-Processing | 16 | March 14, 2016 04:25 |
Gambit - meshing over airfoil wrapping (?) problem | JFDC | FLUENT | 1 | July 11, 2011 06:59 |
Turbulence dampening due to magnetic field in LES and RAS | eelcovv | OpenFOAM | 0 | June 8, 2010 12:35 |
Aeroacustic problem in Automotive field | Gabriele Velenich | Main CFD Forum | 5 | December 11, 2001 04:43 |
extremely simple problem... can you solve it properly? | Mikhail | Main CFD Forum | 40 | September 9, 1999 10:11 |